开发者

Getting NullReferenceException was unhandled

开发者 https://www.devze.com 2023-02-07 11:43 出处:网络
This is开发者_StackOverflow社区 what I entered.It will build with no errors.But gives me the null error on:

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

精彩评论

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