Hi,
I have one Web form clicking on save button i want to create DB and Some Sql Script i want to execute under that DB which ever i created.
I coded like this but it is throwing error .
Error is Failure to connect Server name ,DB name ,USer ID and Password it is throwing.
protected void DBCreation()
{
System.Data.SqlClient.SqlConnection tmpConn;
string sqlCreateDBQuery;
tmpConn = new SqlConnection();
DataSet ds = new DataSet();
ds = clsNewcompany.GetServerName();
string ServerName = ds.Tables[0].Rows[0]["ServerName"].ToString();
tmpConn.ConnectionString = "SERVER = " + ServerName +"; DATABASE = master; User ID = sa; Pwd = chirag12";
sqlCreateDBQuery = " CREATE DATABASE "
+ txtCompany.Text.Trim().ToString();
FileInfo file = new FileInfo(@"E:\tab.sql");
SqlCommand myCommand = new SqlCommand(sqlCreateDBQuery, tmpConn);
try
{
tmpConn.Open();
myCommand.ExecuteNonQuery();
tmpConn.Close();
string script = file.OpenText().ReadToEnd();
tmpConn.ConnectionString = "SERVER = " + ServerName + "; DATABASE = " + txtCompany.Text.Trim().ToString() + "; User ID = sa; Pwd = chirag12";
Server server = new Server(new ServerConnection(tmpConn.ConnectionString));
tmpConn.Open();
server.ConnectionContext.ExecuteNonQuery(script);
file.OpenText().Close();
}
catch (Exception ex)
{
}
}
Please help me any one....