2

Every time I try to run a unit test with some test methods, I get a NullReferenceException at the first line of the following :

    public DB()
    {            
        this.sqlConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        this.con = new SqlConnection(this.sqlConnectionString);
        this.con.StateChange += new StateChangeEventHandler(this.Connection_StateChange);
    }

After further research I realized I should add an app.config file to my test project. I have no clue what to do with it or what it's used for, though.

Tips on how to proceed?

1 Answer 1

1

You need to add a new Connection String section in your app.config with the name ConnectionString (Since that is what you're referencing in your C# code):

<configuration>
    <connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=YourDataSource;Initial Catalog=YourDatabase;IntegratedSecurity=True" providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

You will also need to change the actual connectionString value in the app.config file.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.