I developed a winforms app locally on my machine. It reads data from a csv file and looks up related information from a database (by executing a stored proc).
I moved that to the development server and tried running it, but I get an error when at the line that gets SQL connection string from app.config file. The error is: System.NullReferenceException: Object reference not set to an instance of an object.. Of course the app runs fine on my machine.
I commented out all lines following this code, and the error message is displayed. I am guessing it has to do with the conn.ConnectionString line.
The SQL database is pointing to the correct db server & UID & pwd are correct. What would be causing the error?
try
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["SilverTicker"].ConnectionString;
One of the objects in your code sample is returning “null”. I’m guessing that it’s
Put a breakpoint on that line and check the contents of the
.ConnectionStringscollection to be sure that it contains “SilverTicker”.I’m guessing that
ConfigurationManager.ConnectionStrings["SilverTicket"]is undefined (probably because of an inconsistency betweenapp.configin the two environments), so accessing it’s.ConnectionStringproperty is throwing an exception.