开发者

Getting NullReferenceException was unhandled

This is开发者_StackOverflow社区 what I entered. It will build with no errors. But gives me the null error on:

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

I am using 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();


The problem is that you're trying to find a connection string *called "Data Source=sql1..." in your settings whereas you want to actually treat that literal value as the connection string.

If you really want to hard code your connection string, just use:

string connectionString = "Data Source=sql1 [etc]";
MySqlConnection = new SqlConnection(connectionString);
// etc
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜