我从事 C# 项目 (WinForm)
我在客户端 PC 上安装 Sql Server 2008 Express。
在我的程序开始必须创建一个数据库。所以我使用此代码创建数据库:
string sqlCreateDBQuery;
SqlConnection tmpConn = new SqlConnection(@"SERVER =.\SQLEXPRESS; Trusted_Connection = yes;DATABASE = master;");
sqlCreateDBQuery = " CREATE DATABASE "
+ DatabaseName
+ " ON PRIMARY "
+ " (NAME = " + DatabaseName + ", "
+ " FILENAME = '" + @"C:" + @"\" + DatabaseName + ".mdf" + "', "
+ " SIZE = 3MB,"
+ " FILEGROWTH = " + "10%" + ") "
+ " LOG ON (NAME =" + "MyDatabase_Log" + ", "
+ " FILENAME = '" + @"C:" + @"\" + DatabaseName + "_log.ldf" + "', "
+ " SIZE = 1MB, "
+ " FILEGROWTH = " + "10%" + ") ";
sqlCreateDBQuery = Coomand;
SqlCommand myCommand = new SqlCommand(sqlCreateDBQuery, tmpConn);
try
{
tmpConn.Open();
MessageBox.Show(sqlCreateDBQuery);
myCommand.ExecuteNonQuery();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
tmpConn.Close();
}
return;
但是当我的程序运行时,我看到以下错误
我的问题是什么?