Friday, February 24, 2012

connection string problem...

I am experiencing a strange problem at the moment:

Basically, I have a webconfig file with the connection string to a sql server database.

I have 2 pages...both reference the connection string in the web config file...

the first page is a logon page - this accesses the database and executes properly, however, the second page raises an exception when opening the connection with the following

"The connectionString property has not been initialized".

As an additional note, I have pulled source code from 2 different machines and done a rebuild on the project - not sure why this would have a bearing on it but maybe I am missing something.

Anyone shed any light on it?

Thanks in advance!Can you post your web.config string and the one used in code
There may be a possibility that name in web.config and the one used in code are not in same case...or there is typo...|||The definition in the program is:

Dim cnRobDb As New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))

and within the web config file:

<appSettings>
<add key="connectionString" value="data source=RobSQL;initial catalog=Robdb;user id=sa;pwd=??" />
</appSettings>|||Does it give error when you use


Dim cnRobDb As New SqlConnection("data source=RobSQL;initial catalog=Robdb;user id=sa;pwd=??" )

|||Tried coding as suggested and no it doesn't work - still get the same error. Like I say the wierd thing is that it the other program that runs first, the connection is made and data accessed correctly...mmm very strange.|||Can you post your code
Where are you writing the code for SqlConnection??|||Sushila,

thanks for taking the time to read and respond to this query, your help and time is very much appreciated!

I have solved the problem and interesting it was too. Basically, I had 2 versions of the .netframework installled: 1.0.3705 and 1.1 (installed simultaneosly).

This has not proved a problem until I imported code from another developer. It was importing the code that seems to have brought the problem out into the open. I removed version 1.1 and the problem has now disappeared! The database connection string in all code was identical and was stored in the web.config file but as shown in previous posts was manifesting a "connection not initialized" in certain programs but not others.

Thanks :)
Rob.

No comments:

Post a Comment