h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Get DataBase Exists or not using DataContext

               Today, we discussed about "Get DataBase Exists or not using DataContext in C#.net"
DataContext context = new DataContext(GetConnectionString("YourServerName"));
bool dbExists = context.DatabaseExists();
if (dbExists)
{
MessageBox.Show("Database Exists");
}
else
{
MessageBox.Show("Database doesn't Exist");
}
Get Connection string Method
static string GetConnectionString(string serverName)
{
System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
builder["Data Source"] = serverName; builder["integrated Security"] = true; builder["Initial Catalog"] = "Sample2";
Console.WriteLine(builder.ConnectionString);
Console.ReadKey(true);
return builder.ConnectionString;
}

DataContext

DataContext:
  1.     To communicate with a Database a connection must be made. In LINQ this connection is created by a DataContext.
  2. Create connection to database.
  3. It submits and retrieves object to database.
  4. Converts objects to SQL queries and vice versa.