当前位置: 代码迷 >> Sql Server >> 请问C#创建SQL SERVER数据库的有关问题
  详细解决方案

请问C#创建SQL SERVER数据库的有关问题

热度:62   发布时间:2016-04-24 19:35:53.0
请教C#创建SQL SERVER数据库的问题
网上拷的一份代码

        public static string DB_NAME = "mydb"; 
        //public static string DB_PATH = "C:\\data\\";
        public static string DB_PATH = "C:\\";
        public static bool CreateDatabase()
        {
            bool stat = true;
            string sqlCreateDBQuery;
            SqlConnection myConn = 
                new SqlConnection("Server=localhost\\SQLEXPRESS;Integrated security=SSPI;database=master;");

            sqlCreateDBQuery = " CREATE DATABASE "
                                + DB_NAME
                                + " ON PRIMARY "
                                + " (NAME = " + DB_NAME + "_Data, "
                                + " FILENAME = '" + DB_PATH + DB_NAME + ".mdf', "
                                + " SIZE = 3MB,"
                                + " FILEGROWTH = 10%) "
                                + " LOG ON (NAME =" + DB_NAME + "_Log, "
                                + " FILENAME = '" + DB_PATH + DB_NAME + "Log.ldf', "
                                + " SIZE = 1MB, "
                                + " FILEGROWTH = 10%) ";

            SqlCommand myCommand = new SqlCommand(sqlCreateDBQuery, myConn);
            //try
            //{
            myConn.Open();
            // 下面这句报了异常
            //CREATE FILE encountered operating system error 5(error not found) while attempting
            //to open or create the physical file 'C:\mydb.mdf'.
            //这是什么原因呢?
            myCommand.ExecuteNonQuery();
   
            return stat;
        }

------解决方案--------------------
CREATE FILE encountered operating system error 5(error not found) while attempting
  相关解决方案