在網(wǎng)站找到了實現(xiàn)方法,但是打包后的EXE文件無法安裝數(shù)據(jù)庫,小弟不才,敬請大俠指教!
我的實現(xiàn)代碼:
private void ExecuteSql(string conn, string DatabaseName, string Sql)??????? {??????????? SqlConnection mySqlConnection = new SqlConnection(conn);??????????? SqlCommand Command = new SqlCommand(Sql, mySqlConnection);??????????? mySqlConnection.Open();??????????? mySqlConnection.ChangeDatabase(DatabaseName);??????????? try??????????? {??????????????? Command.ExecuteNonQuery();??????????? }??????????? finally??????????? {??????????????? //close Connection? ??????????????? mySqlConnection.Close();??????????? }??????? }
public override void Install(System.Collections.IDictionary stateSaver)??????? {??????????? base.Install(stateSaver);
??????????? // ------------------------建立數(shù)據(jù)庫-------------------------------------------------
??????????? try??????????? {??????????????? string connstr = String.Format("data source={0};user id={1};password={2};persist security info=false;packet size=4096", Context.Parameters["server"], Context.Parameters["user"], Context.Parameters["pwd"]);??????????????? //'根據(jù)輸入的數(shù)據(jù)庫名稱建立數(shù)據(jù)庫? ??????????????? ExecuteSql(connstr, "master", "CREATE DATABASE " + Context.Parameters["dbname"]);??????????????? //'調用osql執(zhí)行腳本? ??????????????? Process sqlprocess = new System.Diagnostics.Process();??????????????? sqlprocess.StartInfo.FileName = "osql.exe ";??????????????? sqlprocess.StartInfo.Arguments = String.Format(" -U {0} -P {1} -d {2} -i {3}ACM618DeviceInfo.sql", Context.Parameters["user"], Context.Parameters["pwd"], Context.Parameters["dbname"], Context.Parameters["targetdir"]);??????????????? sqlprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;??????????????? sqlprocess.Start();??????????????? sqlprocess.WaitForExit(); // '等待執(zhí)行??????????????? sqlprocess.Close();
??????????????? //'刪除腳本文件??????????????? FileInfo sqlfileinfo = new FileInfo(String.Format("{0}ACM618DeviceInfo.sql", Context.Parameters["targetdir"]));
??????????????? if (sqlfileinfo.Exists)??????????????? {??????????????????? sqlfileinfo.Delete();??????????????? }??????????? }??????????? catch (Exception ex)??????????? {??????????????? throw ex;??????????? }??????? }
安裝程序時提示的錯誤是:
在建立與服務器的連接時出錯。在連接到 SQL Server 2005 時,在默認的設置下 SQL Server 不允許進行遠程連接可能會導致此失敗。 (provider: SQL 網(wǎng)絡接口, error: 25 - 連接字符串無效)
請問我程序中寫的是哪個字符串出問題了??
我是剛剛注冊的新手,分不多··給個意思···多多原諒!
- 3 回答
- 0 關注
- 325 瀏覽
添加回答
舉報
0/150
提交
取消