Reputation: 440
i have this statement that highlighted after i debug the program. i don't know how to fix this can someone help me please.
string constr = ConfigurationManager.ConnectionStrings["Server=LUIGEL-PC\\SQLExpress;Database=StudentInfo;Trusted_Connection=Yes"].ConnectionString;
is there a problem with this line? i'm connecting to a localdb.
Upvotes: 2
Views: 43
Reputation: 25352
In this line require key name of this value from web.config
ConfigurationManager.ConnectionStrings["Server=LUIGEL-PC\\SQLExpress;Database=StudentInfo;Trusted_Connection=Yes"].ConnectionString;
As it's not found any key name Server=LUIGEL-PC\\SQLExpress;Database=StudentInfo;Trusted_Connection=Yes
in ConnectionStrings
node, it's throwing NullReferenceException
Try like this
web.config
<connectionStrings>
<add
name="myConnectionString"
connectionString="Data Source=serverName;Initial
Catalog=Northwind;Persist Security Info=True;User
ID=userName;Password=password"
providerName="System.Data.SqlClient"/>
</connectionStrings>
C#
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
Upvotes: 2