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;
}