Automate registering a DSN
-
I have been researching for ways to automatically create a SQL Server DSN on a local machine for a application and include it in the installation of the client to eliminate a user attempting to set the DSN themselves. I have found a couple of examples inserting information into the registry, but I do not want to do it this way. I found a vague article on the use of DBEngine.RegisterDatabase function, but am unable to find details. Has anyone performed this in the past? :~
-
I have been researching for ways to automatically create a SQL Server DSN on a local machine for a application and include it in the installation of the client to eliminate a user attempting to set the DSN themselves. I have found a couple of examples inserting information into the registry, but I do not want to do it this way. I found a vague article on the use of DBEngine.RegisterDatabase function, but am unable to find details. Has anyone performed this in the past? :~
Any reason why you don't want to go with the registry? Microsoft even recommends it: HOWTO: Programmatically Create a DSN for SQL Server with VB http://support.microsoft.com/default.aspx?scid=KB;en-us;q184608
-
I have been researching for ways to automatically create a SQL Server DSN on a local machine for a application and include it in the installation of the client to eliminate a user attempting to set the DSN themselves. I have found a couple of examples inserting information into the registry, but I do not want to do it this way. I found a vague article on the use of DBEngine.RegisterDatabase function, but am unable to find details. Has anyone performed this in the past? :~
check out the documentation on
SQLConfigDataSource
function from odbccp32.dll... Alexandre Kojevnikov MCP (SQL2K) Leuven, Belgium -
I have been researching for ways to automatically create a SQL Server DSN on a local machine for a application and include it in the installation of the client to eliminate a user attempting to set the DSN themselves. I have found a couple of examples inserting information into the registry, but I do not want to do it this way. I found a vague article on the use of DBEngine.RegisterDatabase function, but am unable to find details. Has anyone performed this in the past? :~
Heres some code I have been using: // Create ODBC Datasource //////////////////////////////////////////////// char szConfig[256] = ""; sprintf(szConfig, "DSN=MyDSN\0Description=My Description\0DBQ=%s\0UID=Admin\0\0", m_sDatabasePath); SQLConfigDataSource(NULL, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)\0", szConfig ); ////////////////////////////////////////////////////////////////////////// You might need to modify it slightly for SQL Server. I just run this in InitInstace, there is no need to check if it exists since it will just be overwritten if it does.