Q1: This example (not tested) is how you could write a function to determine whether a database exists (using our internal ODBC wrapper classes).
BOOL DoesDatabaseExist(char *cpDBName, char *cpDSN, char *cpUserID, char *cpPassword)
{
BOOL bDBExists = FALSE;
DBConnection oDBConn;
if (oDBConn.Connect(cpDSN,cpUserID,cpPassword))
{
char caBuf[256];
sprintf(caBuf,"select COUNT(\*) from master..sysdatabases where name = '%s'",cpDBName);
DBStatement \*pStmt = oDBConn.ExecSQL(caBuf);
if (pStmt)
{
if (pStmt->FetchNext())
bDBExists = pStmt->GetShort(1);
pStmt->EndSQL();
delete pStmt;
}
else
DoDBError("Select Error",&oDBConn);
oDBConn.Disconnect();
}
else
DoDBError("Connection Failed!",&oDBConn);
return bDBExists;
}
Q2: Using the same form as above, you would execute the CREATE DATABASE command instead of a select. Note that the CREATE DATABASE command does not return any result sets. For more info, see CREATE DATABASE in SQL BOL. Q3: Post to C# forum... I do C but I am not sharp ;P onwards and upwards...