Database Existence Checking
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using net.ERP.Constants;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace net.ERP.DatabaseSchema.DBExistanceChecking
{
class DatabaseExistanceChecking:CommonConstants
{
public bool mpubbIsDatabaseExists(string pstrServerName)
{
SqlConnection lprisqlconnSQLConnection = new SqlConnection("Server=" + pstrServerName + ";Integrated security=SSPI;database=master");
try
{
lprisqlconnSQLConnection.Open();
SqlCommand lsqlcommSQLCommand = lprisqlconnSQLConnection.CreateCommand();
lsqlcommSQLCommand.CommandText = "SELECT COUNT(*) AS TOTAL_RECORDS FROM master.dbo.sysdatabases WHERE NAME = 'NET_ERP_REMS'";
SqlDataReader lsqldrSqlDataReader = lsqlcommSQLCommand.ExecuteReader();
if (lsqldrSqlDataReader.Read())
{
int liTotalDatabases = (int)lsqldrSqlDataReader["TOTAL_RECORDS"];
lsqldrSqlDataReader.Close();
if (liTotalDatabases > 0)
{
return true;
}
else
{
return false;
}
}
return true;
}
catch (Exception pexpDBExistance)
{
MessageBox.Show(pexpDBExistance.ToString(), gmpubcstrUserConfirmation, MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
finally
{
if (lprisqlconnSQLConnection.State == ConnectionState.Open)
{
lprisqlconnSQLConnection.Close();
}
}
}
}
}
Post a Comment
Oops!
The words you entered did not match the given text. Please try again.
Oops!
Oops, you forgot something.