0

Problem is that when i use

public static SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

I get this error "Object reference not set to an instance of an object" on my main WinForm, where I added 3 UserControls,

Errors Which I get after using the above Code

and when i set connectionstring something like this

public static SqlConnection con = new SqlConnection(@"Data Source=UMAIR-FQ\UMAIR; Initial Catalog=DBMrBurger;Integrated Security=True");

It Works Perfectly Fine but it's not dynamic. I want a dynamic ConnectionString. any suggestion please?

Here is my AppConig ConnectionString,

<connectionStrings> 
   <add name="ConnectionString" 
   connectionString="Data Source=UMAIR-FQ\UMAIR; Initial Catalog=DBMrBurger;Integrated Security=True"
   providerName="System.Data.SqlClient" />
</connectionStrings>
Filburt
  • 17,626
  • 12
  • 64
  • 115
  • What do you get if you try to get the connection string into a string variable? Most likely, your App.config cannot be found - make sure it matches your application name and is placed in your application folder. – Filburt Mar 14 '20 at 09:47
  • i Tried String ConnectionString variable too – Umair Farooq Mar 14 '20 at 09:49

0 Answers0