Database existense in SQL Server ?
-
Hi, Am facing problems in following........... 1. How to know whether Database exist in SQL Server 2. How to Create just Database name in SQL Server I need code solutoin in VC++ 6.0 3. How to give option of, Download a HTML FIle Directly, without displaying SaveAs Dialog Box.....in C#.NET Babar
-
Hi, Am facing problems in following........... 1. How to know whether Database exist in SQL Server 2. How to Create just Database name in SQL Server I need code solutoin in VC++ 6.0 3. How to give option of, Download a HTML FIle Directly, without displaying SaveAs Dialog Box.....in C#.NET Babar
Ask the third question in the C# forum. Christian Graus - Microsoft MVP - C++
-
Hi, Am facing problems in following........... 1. How to know whether Database exist in SQL Server 2. How to Create just Database name in SQL Server I need code solutoin in VC++ 6.0 3. How to give option of, Download a HTML FIle Directly, without displaying SaveAs Dialog Box.....in C#.NET Babar
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...