我创建了一个运行 MS SQL 的 Amazon AWS RDS 实例。我已经成功地能够使用 C# 以编程方式创建数据库:
SqlConnection myConn = new SqlConnection("Data Source=<public-ip-name>;Persist Security Info=True;User ID=<userid>;PWD=<pwd>;");
myConn.Open();
string str = "CREATE DATABASE contacts";
SqlCommand cmd = new SqlCommand(str, myConn);
cmd.ExecuteNonQuery();
但是,我无法制作更复杂的连接字符串:
str = "CREATE DATABASE contacts ON PRIMARY " +
"(NAME = Contacts_Data, " +
@"FILENAME = 'c:\contacts.mdf', " +
"SIZE = 4MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = Contacts_Log, " +
@"FILENAME = 'c:\contacts.ldf', " +
"SIZE = 1MB, " +
"MAXSIZE = 5MB, " +
"FILEGROWTH = 10%)";
错误 (5) 似乎抱怨 C:\ 无法写入。也许它不存在?如果我省略 FILENAME,则会出现错误提示我省略了它。FILENAME 的正确值是多少?看来 FILENAME 必须指定一个现有的文件路径。