新手 :C#创建数据库,下面是我的代码,帮忙找出错误,运行时出错弹出对话框, 5
try{stringmyExecuteQuery="CREATEDATABASEmydbONPRIMARY"+"(name=test_data,filename='D:\...
try
{
string myExecuteQuery = "CREATE DATABASE mydb ON PRIMARY"
+ "(name=test_data, filename = 'D:\\mysql\\mydb_data.mdf', size=3,"
+ "maxsize=5, filegrowth=10%) log on"
+ "(name=mydbb_log, filename='D:\\mysql\\mydb_log.ldf',size=3,"
+ "maxsize=20,filegrowth=1)";
SqlConnection mySqlConnection = new SqlConnection("server=SQLSERVER;user id=sa;password=abc;Trusted_Connection=yes;User Instance=True");
SqlCommand myCommand = new SqlCommand(myExecuteQuery, mySqlConnection);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
mySqlConnection.Close();
}
catch
{
MessageBox.Show(" 出错");
}
还真不行,不知是不是平台的问题,你们可以给我你们测试成功的代码。 展开
{
string myExecuteQuery = "CREATE DATABASE mydb ON PRIMARY"
+ "(name=test_data, filename = 'D:\\mysql\\mydb_data.mdf', size=3,"
+ "maxsize=5, filegrowth=10%) log on"
+ "(name=mydbb_log, filename='D:\\mysql\\mydb_log.ldf',size=3,"
+ "maxsize=20,filegrowth=1)";
SqlConnection mySqlConnection = new SqlConnection("server=SQLSERVER;user id=sa;password=abc;Trusted_Connection=yes;User Instance=True");
SqlCommand myCommand = new SqlCommand(myExecuteQuery, mySqlConnection);
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
mySqlConnection.Close();
}
catch
{
MessageBox.Show(" 出错");
}
还真不行,不知是不是平台的问题,你们可以给我你们测试成功的代码。 展开
展开全部
都扯淡,我整了10多分钟才正好~你连接字符串有问题,改成我的写的立马好使!
//SqlConnection mySqlConnection = new SqlConnection("server=.;Data Source=master; uid=sa;password=abc;Trusted_Connection=yes;User Instance=True");
这个是我的
SqlConnection mySqlConnection = new SqlConnection("Persist Security Info=False;User ID=sa;Password=abc;Initial Catalog=master;Server=.");
你自己试试,再报错,脑袋给你
//SqlConnection mySqlConnection = new SqlConnection("server=.;Data Source=master; uid=sa;password=abc;Trusted_Connection=yes;User Instance=True");
这个是我的
SqlConnection mySqlConnection = new SqlConnection("Persist Security Info=False;User ID=sa;Password=abc;Initial Catalog=master;Server=.");
你自己试试,再报错,脑袋给你
展开全部
把string myExecuteQuery = "CREATE DATABASE mydb ON PRIMARY"
改成
string myExecuteQuery = "USE master GO; CREATE DATABASE mydb ON PRIMARY"
改成
string myExecuteQuery = "USE master GO; CREATE DATABASE mydb ON PRIMARY"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
弹出什么错误?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建库需要切换到master库下才可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询