日期:2014-05-18 浏览次数:20794 次
string connStr = string.Format("data source={0};user id={1};password={2};persist security info=false;packet size=4096", this.Context.Parameters["server"], this.Context.Parameters["user"], this.Context.Parameters["pwd"]); ExecuteSql(connStr, "master", "CREATE DATABASE " + "数据库名称 "); Process sqlProcess = new Process(); sqlProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; sqlProcess.StartInfo.FileName = "osql.exe"; sqlProcess.StartInfo.Arguments = string.Format("-S {0} -U {1} -P {2} -d {3} -i {4}", "server", "user","pwd", "dbname", "安装文件的路径\*.sql"); sqlProcess.Start(); sqlProcess.WaitForExit(); sqlProcess.Close();
------解决方案--------------------
private void ExecuteSql(string connStr, string DatabaseName, string Sql) { SqlConnection conn = new SqlConnection(connStr); SqlCommand cmd = new SqlCommand(Sql, conn); conn.Open(); conn.ChangeDatabase(DatabaseName); try { cmd.ExecuteNonQuery(); } finally { conn.Close(); } }
------解决方案--------------------
up