This is code for Get DataBase Exists or not using DataContext
DataContext context = new DataContext(GetConnectionString("YourSErverName"));
bool dbExists = context.DatabaseExists();
if (dbExists)
{
MessageBox.Show("Database Exists");
}
else
{
MessageBox.Show("Database doesn't Exist");
}
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;
}
bool dbExists = context.DatabaseExists();
if (dbExists)
{
MessageBox.Show("Database Exists");
}
else
{
MessageBox.Show("Database doesn't Exist");
}
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;
}
No comments:
Post a Comment