Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Database existense in SQL Server ?

Database existense in SQL Server ?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpdatabasec++htmlsql-server
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Babarsaeed
    wrote on last edited by
    #1

    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

    C B 2 Replies Last reply
    0
    • B Babarsaeed

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Ask the third question in the C# forum. Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      • B Babarsaeed

        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

        B Offline
        B Offline
        basementman
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups