gpt4 book ai didi

"CREATE DATABASE"语句的 C# 和 SQL Server 错误

转载 作者:搜寻专家 更新时间:2023-10-30 21:53:29 27 4
gpt4 key购买 nike

这是我的代码:

String str;
SqlConnection myConn = new SqlConnection("Server=localhost;Integratedsecurity=SSPI;database=master");

str = "CREATE DATABASE JoesData ON PRIMARY " +
"(NAME = JoesData, " +
"FILENAME = 'C:\\JoesData.mdf', " +
"SIZE = 3MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = MyDatabase_Log, " +
"FILENAME = 'C:\\MyJLog.ldf', " +
"SIZE = 1MB, " +
"MAXSIZE = 5MB, " +
"FILEGROWTH = 10%)";

SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
}
}

这里是错误: enter image description here

知道是什么原因造成的吗?在此先感谢您的帮助。

最佳答案

您的数据库连接失败。检查您的安装和连接字符串。

关于 "CREATE DATABASE"语句的 C# 和 SQL Server 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7013397/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com