Created DB
public bool CreateCompanyDatabase(string CN)
{
String str;
SqlConnection myConn = new SqlConnection("Server=ESTSYS4-PC;database=master;uid=sa;pwd=est$123;");
str = "USE MASTER CREATE DATABASE " + CN;
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
MessageBox.Show("DataBase is Created Successfully", "ISELLit", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(), "ISELLit", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
}
}
}
Script Method
public void CreateScript(string CN)
{
string SQLscript = null;
FileInfo file = new FileInfo(@"C:\Users\ESTSYS4\Desktop\Design\ISELLIT\UIDESIGN\ISELLIT\ISELLIT\bin\Debug\Script\ISELLit_temp.sql");
string script = file.OpenText().ReadToEnd();
SQLscript = script.Replace("GO", "");
SqlConnection conn = new SqlConnection("Server=ESTSYS4-PC;database=" + CN + ";uid=sa;pwd=est$123;");
SqlCommand Cmd = new SqlCommand(SQLscript, conn);
try
{
conn.Open();
Cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "ISELLit", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
}