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#
  4. Check database if exist

Check database if exist

Scheduled Pinned Locked Moved C#
csharpdatabasesysadmintutorialquestion
5 Posts 4 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.
  • C Offline
    C Offline
    C Coudou
    wrote on last edited by
    #1

    how to check database if exist on the server using c#? thanks in advance, :)

    ****************************** I just want to know everything

    A V P 3 Replies Last reply
    0
    • C C Coudou

      how to check database if exist on the server using c#? thanks in advance, :)

      ****************************** I just want to know everything

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      use microsoft sqlserver connection info dll files private static Server srvSql; private static ServerConnection srvConn; void ReadDatabase(string _ServerName) { try { srvConn = new ServerConnection(_ServerName); srvConn.LoginSecure = true; srvSql = new Server(srvConn); foreach (Database MyServer in srvSql.Databases) { cmboDB.Items.Add(MyServer.Name); //Here you can check wheather database exist or not } } catch (Exception DbExp) { MessageBox.Show("Error in Connection !!!!", "Database ", MessageBoxButtons.OK, MessageBoxIcon.Error); } }

      Best Regards ----------------- Abhijit Jana View My CodeProject Articles "Success is Journey it's not a destination"

      1 Reply Last reply
      0
      • C C Coudou

        how to check database if exist on the server using c#? thanks in advance, :)

        ****************************** I just want to know everything

        V Offline
        V Offline
        Venki56
        wrote on last edited by
        #3

        Take One Textbox anb Button........ Write the following code for Button click.... SqlConnection cn = new SqlConnection("server=ms08; uid=sa; pwd=;"); string Qry ="SELECT Count(*) FROM master.dbo.sysdatabases WHERE name = '" + TextBox1.Text + "'"; SqlDataAdapter da = new SqlDataAdapter(Qry,cn); DataSet ds =new DataSet(); da.Fill(ds); DataRow dr=ds.Tables[0].Rows[0]; if(dr[0].ToString() == "1") MessageBox.Show(Exists..") else MessageBox.Show("Does not exists....");

        venki

        1 Reply Last reply
        0
        • C C Coudou

          how to check database if exist on the server using c#? thanks in advance, :)

          ****************************** I just want to know everything

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          Try to connect to the database and catch any exceptions that it may throw back at you about not being able to connect to the specified database.

          "Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus

          C 1 Reply Last reply
          0
          • P Paul Conrad

            Try to connect to the database and catch any exceptions that it may throw back at you about not being able to connect to the specified database.

            "Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus

            C Offline
            C Offline
            C Coudou
            wrote on last edited by
            #5

            to Abhijit Jana , Venki56 and Paul Conrad Thanks for your help, Cheers.:-D

            ****************************** I just want to know everything

            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