Check database if exist
-
how to check database if exist on the server using c#? thanks in advance, :)
****************************** I just want to know everything
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"
-
how to check database if exist on the server using c#? thanks in advance, :)
****************************** I just want to know everything
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
-
how to check database if exist on the server using c#? thanks in advance, :)
****************************** I just want to know everything
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
-
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