This is just another SQL C# articles which let you learn how to check for a database existence on SQL Server.
All you have to do query names in sys.databases table and make sure it is available to use. You can create a function for the purpose.
public static bool IsDBExist(string server, string db)
List<string> list = new List<string>();
// Open connection to the database
string conString = null; ;
conString = "server=" + server + ";uid=sa;";
bool has = false;
using (SqlConnection con = new SqlConnection(conString))
if (con.State == ConnectionState.Open) con.Close();
// Set up a command with the given query and associate
// this with the current connection.
using (SqlCommand cmd = new SqlCommand("SELECT name from sys.databases where name='" + db + "'", con))
using (IDataReader dr = cmd.ExecuteReader())
if (list.Count > 0) has = true;
catch (Exception er)
Wanna migrating Access database to MS SQL Server? You have two options; programmatically deal the transaction with the new database or use Microsoft SQL Server Migration Assistant for Access and migrate the database directly to a newly created database to SQL Server 2005 or later versions
Before starting with MSSQLMA Note the following
Prepare your database
Check your Access database version, whether it is 32 or 64 database. If it is 32 make sure that you run 32 version of MSSQLMA which can be found under Microsoft SQL Server Migration Assistant for Access folder.
There are different versions of MSSQLMA available for different versions of the Access database.
Download Migration Assistant for Windows
Use the following link to download the free Migration Assistant from Microsoft official website.
The following example simply illustrate how you can delete rows using dataset and command builder in C#. As a C# programmer you may know how important a dataset is.
Here in our example, we first create a database adapter pointing to some table rows and then build a dataset which is the local representation of database table.
Common.StockPurchase_Part = new SqlDataAdapter("select * from purchasepart where billno=" + bno, Common.con);
Common.StockPurchasePartDataset = new DataSet();
Now lets create a command builder and configure the delete command of the adapter.
Common.cmdbuilder = new System.Data.SqlClient.SqlCommandBuilder(Common.StockPurchase_Part);
Common.StockPurchase_Part.DeleteCommand = Common.cmdbuilder.GetDeleteCommand();
Now we need to mark the rows we want to delete, using the Rows collection. In my example , I have only one rows, which is stored in the 0th position. So my code will look like