网上拷的一份代码
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