Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Creating a SQL Server DSN programatically


1 reply to this topic

tSunami akp

tSunami akp
  • Members
  • 12 posts

Posted 13 March 2002 - 06:44

As a part of my product I am supposed to create SQL Server DSN.

I have tried using the SQLConfigDataSource as follows:
Code Sample

#include <stdio.h>
#include <windows.h>
#include <sql.h>
#include <odbcinst.h>

void main()
{
RETCODE retcode;
UCHAR    *szDriver = "SQL Server";
UCHAR    *szAttributes = "DSN=SQL07\0"
"UID=sa\0"
"PWD=sa\0"
"Address=SIS-003"
"WSID=KAVERI\0"
"SERVER=SIS-004\0";


retcode = SQLConfigDataSource(NULL,
                            ODBC_ADD_DSN,
                            szDriver,
                            szAttributes);

if(retcode)
printf("Successful");
else
printf("Unsuccessful");
}


The retcode is unsuccessful.

One more matter is that I need to do the same in InstallShield Professional. Which is the DLL that contains this API? What are the other DLL(s) that are dependent on this DLL.
Arun Kumar. P[br]Member - Project Management[br]tSunami InfoSolutions Pvt Ltd

Marie Tupps

Marie Tupps
  • Members
  • 22 posts

Posted 19 March 2002 - 14:35

Hi,

Try this:
#define ODBC_KEY  "\\SOFTWARE\\ODBC\\ODBC.INI\\MYDATABASE"
#define ODBC_KEY2  
"\\SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources"

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
nResult = RegDBKeyExist(ODBC_KEY);                  
szClass = "";
nvType = REGDB_STRING;
if(nResult < 1) then            //DOES NOT EXIST..
  RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);    
  RegDBCreateKeyEx ( ODBC_KEY, szClass );    
endif;  

szDatabaseName = MYDATABASE;
svName = "Database";                    

//set the odbc driver based on sql
svValue = SystemFolder ^ "sqlsrv32.dll";    
svName = "Driver";
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
RegDBSetKeyValueEx( ODBC_KEY, svName, nvType, svValue, nvSize );        
 
svValue = "Admin";
svName = "LastUser";

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
RegDBSetKeyValueEx( ODBC_KEY, svName, nvType, svValue, nvSize );

svValue = szMYSERVERNAME;
svName = "Server";                                              

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);  
RegDBSetKeyValueEx( ODBC_KEY, svName, nvType, svValue, nvSize );

//szKey = "\\SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources";  
nvType = REGDB_STRING;
svName = "MYDATABASE" ;
svValue = "SQL Server";
Disable(LOGGING);
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
RegDBSetKeyValueEx( ODBC_KEY2, svName, nvType, svValue, nvSize );
Marie Tupps