Hello I need to create a System DSN ODBC for SQL. I have seen a lot of solutions using DSN-less solutions but that does not work for me.
I have to use this DSN from a third-party application where I don't have its source code. What I want with this simple code is to execute it before the third-party application, just to change some ODBC attributes (using the same DSN name) like Server same, user, password, etc...
I have been able to delete the DSN, but no Create or Modify it.
I am using SQLConfigDataSource function in this way:
#define ODBC_ADD_DSN 1 &&' Add data source
#define ODBC_ADD_SYS_DSN 4 &&' Add data source
#define ODBC_CONFIG_SYS_DSN 5 &&' Configure (edit) data source
#define ODBC_REMOVE_SYS_DSN 6 &&' Remove data source
#define vbAPINull 0 &&' NULL Pointer
DECLARE LONG SQLConfigDataSource IN ODBCCP32.DLL ;
LONG hwndParent, LONG fRequest, STRING lpszDriver, STRING lpszAttributes
strDriver = "SQL Server"
strAttributes = "SERVER=LOCALPC" + Chr(0)
strAttributes = strAttributes + "DESCRIPTION=test" + Chr(0)
strAttributes = strAttributes + "DSN=local_test" + Chr(0)
strAttributes = strAttributes + "DATABASE=master" + Chr(0)
strAttributes = strAttributes + "UID=sa" + Chr(0)
strAttributes = strAttributes + "PWD=temp0" + Chr(0)
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_SYS_DSN, strDriver, strAttributes)
If intRet>0
=MessageBox( "DSN Created" )
Else
=MessageBox( "Create Failed" )
EndIf
All the time I got the message "Create Failed". Why this could be happening?