>I'm trying to connect to an ODBC datasource using the SqlStringConnect function, but i'm getting a 1903 error, 'String is too long to fit'.
>
>The connection string is greater than 255 characters, and i have no way of reducing its length. It contains a series of file names including paths and an unlock key which is 128 characters long.
>
>Any ideas how i can still use this function, so i can save myself from having to use oledb, which doesn't appear to have the 255 character restriction on a connection string.
Wayne,
A string variable can hold up to 16Mb (that's what docs say, actually holds more). OTOH a string 'literal' is limited to 255 in length. All you need is to avoid literals longer than 255. ie:
strCon = "Driver = ... - this string is up to 255 -" + ;
" another part up to 255 chars"+;
" another part up to 255 chars"+;
" another part up to 255 chars"
And any other method that doesn't directly use literals with over 255 in length would work too(like Borislav showed).
This is not for only connection strings. It applies to any string you need to pass such as property setting in form (PEM sheet limits property text to 255 but in code you can pass the same way, passing a command to SQL pass through etc). ie:
text to m.lcSQLCommand noshow
USE pubs
SELECT SUBSTRING((RTRIM(a.au_fname) + ' ' + LTRIM(a.au_lname)), 1, 25)
AS Name, SUBSTRING(t.title, 1, 20) AS Title
FROM authors a INNER MERGE JOIN titleauthor ta
ON a.au_id = ta.au_id INNER HASH JOIN titles t
ON t.title_id = ta.title_id
ORDER BY au_lname ASC, au_fname ASC
endtext
SQLExec(m.lnHandle,m.lcSQLCommand,'myCursor')
PS: lcCommand sample code is from 'MSSQL books online' as is.
Cetin