hello
asp.net c#,sql server,use sqlhelper class, funcation,class,store procedure,view,triggers,call email class in asp.net c#,MVC AND ENTITY FRAMEWORK TUTORIAL,how to create database with script using c#,datareader with sqlhelper and run time label bind in grid,insert update select storprocedure Delete duplicate record in database,Delete duplicate record in database,how add connection string,how add connection string
Wednesday, 4 December 2013
Monday, 2 December 2013
how to create database with script using c#
using System.IO;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
private void CreateDatabase()
{
String str;
string constr = "Data Source=111.111.1.111;Initial Catalog=master; User Id=sa;Password=password;";
SqlConnection myConn = new SqlConnection(constr);
str = "CREATE DATABASE MyDatabase";
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
}
catch (System.Exception ex)
{
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
string sqlConnectionString = "Data Source=111.111.1.111;Initial Catalog=MyDatabase; User Id=sa;Password=password;";
FileInfo file = new FileInfo("C:\\esage.sql");
string script = file.OpenText().ReadToEnd();
SqlConnection conn = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
}
}
}
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
private void CreateDatabase()
{
String str;
string constr = "Data Source=111.111.1.111;Initial Catalog=master; User Id=sa;Password=password;";
SqlConnection myConn = new SqlConnection(constr);
str = "CREATE DATABASE MyDatabase";
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
}
catch (System.Exception ex)
{
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
string sqlConnectionString = "Data Source=111.111.1.111;Initial Catalog=MyDatabase; User Id=sa;Password=password;";
FileInfo file = new FileInfo("C:\\esage.sql");
string script = file.OpenText().ReadToEnd();
SqlConnection conn = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
}
}
}
Subscribe to:
Posts (Atom)