Link to home
Start Free TrialLog in
Avatar of fpoyavo
fpoyavoFlag for United States of America

asked on

Connection

Hi Experts,

I have error message : (same code and web.conf are used within other pages and works fine.)

The ConnectionString property has not been initialized


Code is :

SqlConnection sqlConnect = new System.Data.SqlClient.SqlConnection();
sqlConnect .ConnectionString = (string)Application["ConnectString"];
sqlConnect .Open();

Thank you.
Avatar of Timbo87
Timbo87

Are you sure you're retrieving the right data? You can test it by copying and pasting the hard-coded connection string in. Obviously don't use this in the final product, but it will be OK for testing. If it works then your problem is with Application["ConnectString"] and if it doesn't then it's a problem with your connection string.
If you get that excaption, then surelly
 
sqlConnect .ConnectionString = null;

which means

(string)Application["ConnectString"] = null;

The problem may be with your config file, or something related with that.
AS Chester_M_Ragel pointed out Application["ConnectString"] = null.  U can test by harcoding the connection string in the program. If it works fine, then u can be sure the problem is with the config file.

The config file should be present in the calling assembly's project output folder, this can either be \bin or \bin\Debug according to the settings
ASKER CERTIFIED SOLUTION
Avatar of seazium
seazium

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial