这是我的问题。我需要让用户选择一个服务器,这样我才能让程序连接到该服务器(SQL注意这是在C#中) 这就是我所做的,但我得到了一个例外
//first I make a variable that equals to a textbox text
//take the variable and I place it where I would put your sever name
//heres my code
string SQLC = (textBox1.Text);
con.ConnectionString = (@"Data Source=FORDS-PC;
Integrated Security=True;
Connect Timeout=15;
Encrypt=False;
TrustServerCertificate=False;
ApplicationIntent=ReadWrite;
MultiSubnetFailover=False");
这里是ERROR
System.InvalidOperationException类型的未处理异常 发生在System.Data.dll)
如果您需要其他任何我需要告诉您的信息,请告诉我
答案 0 :(得分:2)
您需要将数据库添加到连接字符串。
SQL Server连接字符串:
connectionString="Data Source=ServerName; Initial Catalog=DatabaseName;
User ID=UserName;Password=Password
您的代码
string SQLC = textBox1.Text;
con.ConnectionString = ("Data Source=FORDS-PC;Initial Catalog="+SQLC+";Integrated Security=True;Connect
Timeout=15;Encrypt=False;TrustServerCertificate=False;
ApplicationIntent=ReadWrite;MultiSubnetFailover=False");`