How to get a list of databases in an SQL Server (programatically) How do I programatically get a list of all databases on a known server?
What I need is to make my code as flexible as possible. I suceeded in (1) listing all the availble SQL Servers in the domain; (2) I was able to create a DSN in ODBC dynamically but wit a hardcoded database as in
RETCODE retcode;
LPTSTR szDriver = "SQL Server";
char szAttributesChar[255];
// add datasource name if it exixts
dsn_str = "DSN=" + m_MyProgramaticDSN + "\0";
LPTSTR lpszMyProgramaticDSN = new TCHAR[dsn_str.GetLength()+1];
_tcscpy(lpszMyProgramaticDSN, dsn_str);
server_str = "SERVER=" + m_cmbSQLservername + "\0";
LPTSTR lpszSQLservername = new TCHAR[server_str.GetLength()+1];
_tcscpy(lpszSQLservername, server_str);
LPTSTR lpszDATABASE = "DATABASE=VersaScanMeSQL\0";
LPTSTR lpszDESCRIPTION = "DESCRIPTION=Dynamically created datasetname\0";
...
..
// remove the local datasource name if it exixts
TCHAR szAttributesRemove[1028];
TCHAR* szSubStringRemove = &(szAttributesRemove[0]);
// remove an existing DSN
BOOL bretcode = SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, szDriver,
&(szAttributesRemove[0]) /*szAttributes*/);
As you can see, the database is hardcoded. If I can figureout a way of programtically getting it, I will be okay and that is what I am looking for.
Note that I have not yet connected to the database.
__________________ Wango |