zoukankan      html  css  js  c++  java
  • 附加数据库函数

      private void CreateDataBase()
            {
                // 启动SQL服务, 预防装完之后服务未启动
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";

                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;

                p.Start();
                p.StandardInput.WriteLine("net start MSSQL$HW1000");
                p.StandardInput.WriteLine("exit");
                p.StandardOutput.ReadToEnd();

                string strSql = string.Format("server={0}; user id={1}; password={2}; Database=master", "(local)\\SQLEXPRESS", "sa", "sasasa");

               //string strSql = string.Format("Data Source=(local)\\SQLEXPRESS; Initial Catalog=master;Integrated Security=SSPI;");           

                string strMdf = "C:\\新建文件夹http://www.cnblogs.com/lbg280/admin/file://northwnd.mdf/";
                string strLdf = "C:\\新建文件夹http://www.cnblogs.com/lbg280/admin/file://northwnd.ldf/";
                //LogWriter.LogEvent("MDF路径:" + strMdf);                      
                string str;
                SqlConnection myConn = new SqlConnection(strSql);
                str = "EXEC sp_attach_db @dbname = N'NORTHWND', @filename1 = N'" + strMdf + "',@filename2=N'" + strLdf + "'";
                SqlCommand myCommand = new SqlCommand(str, myConn);
                myConn.Open();
                myCommand.ExecuteNonQuery();
                myConn.Close();
            }

  • 相关阅读:
    Shell case esac 和 for
    Shell运算符:Shell算数运算符、关系运算符、布尔运算符、字符串运算符等
    杨辉三角+优化算法
    mount --bind和硬连接的区别
    Linux文件系统管理
    磁盘管理
    Linux之find文件(目录)查找
    BZOJ 3224 平衡树模板题
    NOIP 2016 滚粗记
    BZOJ 4034 线段树+DFS序
  • 原文地址:https://www.cnblogs.com/lbg280/p/1709182.html
Copyright © 2011-2022 走看看