Programmatically Setup ODBC
I had a program in VB6 that set up ODBC drivers for use with my program. It worked fine. I am trying to do a program with similar concepts in VB2008 but I am having problems finding the correct information. I can't make sense of the MSDN ODBC Programmer's Reference and the following code is giving me a problem where marked with the error message
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
It is essentially the same code as I used in VB6 so that could be the problem but it compiled and didn't give me the error until I hit that line. And I doubt there is a problem with my RAM.
Any ideas are greatly appreciated, TIA rasinc
Code:
If (sDBQ = "" And lAction = ODBC_ADD_DSN) Or (sDBQ <> "" And lAction = ODBC_EDIT_DSN) _
Or (sDBQ <> "" And lAction = ODBC_REMOVE_DSN) Then
' check that the file actually exists
If Len(Dir$(sDBFile)) = 0 Then
MsgBox("Database file doesn't exist! ", vbOKOnly + vbCritical)
Exit Sub
End If
sAttributes = "DSN=" & sDSN & vbNullChar & "DBQ=" _
& sDBFile & vbNullChar & "SystemDB=" & sSystemFile & vbNullChar _
& "SERVER=" & strHost & vbNullChar & "Database=boss" & vbNullChar _
& "Port=" & strPort & vbNullChar
lngRet = SQLConfigDataSource(0&, lAction, sDriver, sAttributes) ' problem here "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
End If
Re: Programmatically Setup ODBC
If no one knows the answer to why the memory error message shows up, then does anyone have any idea where some samples might be to programmatically and dynamically change ODBC driver information on-the-fly?
TIA rasinc