0

这是我输入的。它将毫无错误地构建。但是给了我一个空错误:

"MySqlConnection = new SqlConnection"(MyConnectionString.ConnectionString);                    

我正在使用 VS2010 C#...

MyConnectionString = ConfigurationManager.ConnectionStrings["Data Source=sql1;Initial Catalog=DW_screening;Persist Security Info=True;User ID=xxxxx;Password=xxxxxx;Write"];
MySqlConnection = new SqlConnection(MyConnectionString.ConnectionString);                    
MySqlConnection.Open();
MessageBox.Show("Connection Opened Successfully");
//MySqlConnection.Close();
4

1 回答 1

0

问题是您试图在您的设置中找到一个名为“Data Source=sql1...”的连接字符串,而您实际上希望将该文字值视为连接字符串。

如果您真的想对连接字符串进行硬编码,只需使用:

string connectionString = "Data Source=sql1 [etc]";
MySqlConnection = new SqlConnection(connectionString);
// etc
于 2011-01-28T14:12:41.157 回答