posts - 14,  comments - 0,  trackbacks - 0
I got a good MSDN help: Embedding SQL Server Express into Custom Applications
It introduces methods to deploy by a class wrapper. (Usually, we create a setup project and add SQL Express as prerequisite to deploy)
And it also gives an idea to embed *.sql script as text resource and then read, execute the commands one by one:
private SqlConnection sqlCon = new SqlConnection();
private SqlCommand sqlCmd = new SqlCommand();
public string[] ParseScriptToCommands(string strScript)
{
string[] commands;
commands = Regex.Split(strScript, "GO\r\n", RegexOptions.IgnoreCase);
return commands;
}

public bool RunScript(string strFile)
{
string[] strCommands;
strCommands = ParseScriptToCommands(strFile);
try
{
if (sqlCon.State != ConnectionState.Open) sqlCon.Open();

sqlCmd.Connection = sqlCon;

foreach (string strCmd in strCommands)
{
if (strCmd.Length > 0)
{
sqlCmd.CommandText = strCmd;
sqlCmd.ExecuteNonQuery();
}
}
}
catch (SqlException sql_ex)
{
MessageBox.Show(sql_ex.Number.ToString() + " " +
sql_ex.Message.ToString());
return false;
}

return true;
}
Additional resource: Deploy SQL Server databases easily with an Installer class
Tag标签: sql server,deploy
0
0
(请您对文章做出评价)
« 上一篇:Store and retrieve objects in SQL Server
» 下一篇:Installer magic of setup project
posted on 2009-07-31 17:20 Figo Fei 阅读(46) 评论(0)  编辑 收藏 网摘