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

相关文章:

  • 2022-12-23
  • 2021-05-18
  • 2021-07-14
  • 2021-11-16
  • 2021-08-15
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
猜你喜欢
  • 2021-11-01
  • 2021-12-04
  • 2022-12-23
  • 2021-09-05
  • 2021-10-08
  • 2022-01-01
  • 2022-12-23
相关资源
相似解决方案