zoukankan      html  css  js  c++  java
  • Some Sql Server deploy scenarios

    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
  • 相关阅读:
    UVA
    UVA
    UVA
    UVA
    NLP介绍
    新建Springboot项目
    添加ssh密钥
    git 错误合集
    Git入门操作
    Hadoop MapReduce
  • 原文地址:https://www.cnblogs.com/feishunji/p/1536131.html
Copyright © 2011-2022 走看看