By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,045 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

The ConnectionString property has not been initialized

P: n/a
Hi,

I am fairly new to ASP.NET and have been working on a web form that will
allow a user to upload images to a database. I have found a sample web form
that I have been trying to get working, and the web form loads up fine but
upon submitting the image, it comes with the following error:

The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString
property has not been initialized.

Source Error:
Line 129: Try
Line 130:
Line 131: myConnection.Open()
Line 132:
Line 133:
myCommand.ExecuteNonQuery()

I found this script from the following website
http://aspalliance.com/articleViewer.aspx?aId=138&pId=

Can anyone please help I am completely lost as to how to correct this problem.
I am using Visual Studio 2005 beta 1, IIS 6.0, .NET version 2.0.40607 and
SQL Server 2000.

Any help would be greatly appreciated.

Thank,

Devante
Jul 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
The exception is very clear. The ConnectionString property has not been set,
when trying to call Open the SqlConnection object.

So obviously, this property is not being set - hence the connection can't do
it's job.

Looking through the code, it looks like the connection string is being
retrieved from Web.config: Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))

Unless you have a ConnectionString setting in your Web.config with a valid
connection string to your database, this isn't going to work. I am guessing
you never added this setting. Did you think this source code would somehow
know how to connect to your particular sql server? You had to have somehow
specified how to connect.

"Devante" <De*****@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Hi,

I am fairly new to ASP.NET and have been working on a web form that will
allow a user to upload images to a database. I have found a sample web form that I have been trying to get working, and the web form loads up fine but
upon submitting the image, it comes with the following error:

The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString
property has not been initialized.

Source Error:
Line 129: Try
Line 130:
Line 131: myConnection.Open() Line 132:
Line 133:
myCommand.ExecuteNonQuery()

I found this script from the following website
http://aspalliance.com/articleViewer.aspx?aId=138&pId=

Can anyone please help I am completely lost as to how to correct this problem. I am using Visual Studio 2005 beta 1, IIS 6.0, .NET version 2.0.40607 and
SQL Server 2000.

Any help would be greatly appreciated.

Thank,

Devante

Jul 21 '05 #2

P: n/a
Sounds like you did not specify a connection string when creating your
SqlConnection object. If you copied the code from the link that you
specified then you have a line of code looking like this:

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))

This indicates that whoever wrote the code put the connection string in the
appSettings section of the web.config file. If you did not do this then
ConfigurationSettings.AppSettings("ConnectionStrin g") returns null and the
SqlConnection object does not know which database to connect to. So you have
to specify your own connection string instead.

HTH, Jakob.
"Devante" wrote:
Hi,

I am fairly new to ASP.NET and have been working on a web form that will
allow a user to upload images to a database. I have found a sample web form
that I have been trying to get working, and the web form loads up fine but
upon submitting the image, it comes with the following error:

The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString
property has not been initialized.

Source Error:
Line 129: Try
Line 130:
Line 131: myConnection.Open()
Line 132:
Line 133:
myCommand.ExecuteNonQuery()

I found this script from the following website
http://aspalliance.com/articleViewer.aspx?aId=138&pId=

Can anyone please help I am completely lost as to how to correct this problem.
I am using Visual Studio 2005 beta 1, IIS 6.0, .NET version 2.0.40607 and
SQL Server 2000.

Any help would be greatly appreciated.

Thank,

Devante

Jul 21 '05 #3

P: n/a
Hi Jakob

I have created a web.config file and it does have the following info in it:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<appSettings />
<connectionStrings>
<add name="AppConnectionString1"
connectionString="Server=DCKUEPERS-01;Integrated
Security=True;Database=WebDev"
providerName="System.Data.SqlClient" />
</connectionStrings>

But for some reason its still not working what am I doing wrong?
Thank you,

Devante

"Jakob Christensen" wrote:
Sounds like you did not specify a connection string when creating your
SqlConnection object. If you copied the code from the link that you
specified then you have a line of code looking like this:

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))

This indicates that whoever wrote the code put the connection string in the
appSettings section of the web.config file. If you did not do this then
ConfigurationSettings.AppSettings("ConnectionStrin g") returns null and the
SqlConnection object does not know which database to connect to. So you have
to specify your own connection string instead.

HTH, Jakob.
"Devante" wrote:
Hi,

I am fairly new to ASP.NET and have been working on a web form that will
allow a user to upload images to a database. I have found a sample web form
that I have been trying to get working, and the web form loads up fine but
upon submitting the image, it comes with the following error:

The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString
property has not been initialized.

Source Error:
Line 129: Try
Line 130:
Line 131: myConnection.Open()
Line 132:
Line 133:
myCommand.ExecuteNonQuery()

I found this script from the following website
http://aspalliance.com/articleViewer.aspx?aId=138&pId=

Can anyone please help I am completely lost as to how to correct this problem.
I am using Visual Studio 2005 beta 1, IIS 6.0, .NET version 2.0.40607 and
SQL Server 2000.

Any help would be greatly appreciated.

Thank,

Devante

Jul 21 '05 #4

P: n/a
The line ConfigurationSettings.AppSettings("ConnectionStrin g") will not work
with the config file you posted. Are you using this line of code? If yes,
then your config file should look like this:

<appSettings>
<add key="ConnectionString" value="..." />
</appSetting>

Or have you defined a configSection for reading the connection string? In
any case, I don't think you are reading the connection string correctly from
the config file, so you should do some debugging trying to find out what the
problem is.

Regards, Jakob.

"Devante" wrote:
Hi Jakob

I have created a web.config file and it does have the following info in it:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<appSettings />
<connectionStrings>
<add name="AppConnectionString1"
connectionString="Server=DCKUEPERS-01;Integrated
Security=True;Database=WebDev"
providerName="System.Data.SqlClient" />
</connectionStrings>

But for some reason its still not working what am I doing wrong?
Thank you,

Devante

"Jakob Christensen" wrote:
Sounds like you did not specify a connection string when creating your
SqlConnection object. If you copied the code from the link that you
specified then you have a line of code looking like this:

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))

This indicates that whoever wrote the code put the connection string in the
appSettings section of the web.config file. If you did not do this then
ConfigurationSettings.AppSettings("ConnectionStrin g") returns null and the
SqlConnection object does not know which database to connect to. So you have
to specify your own connection string instead.

HTH, Jakob.
"Devante" wrote:
Hi,

I am fairly new to ASP.NET and have been working on a web form that will
allow a user to upload images to a database. I have found a sample web form
that I have been trying to get working, and the web form loads up fine but
upon submitting the image, it comes with the following error:

The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString
property has not been initialized.

Source Error:
Line 129: Try
Line 130:
Line 131: myConnection.Open()
Line 132:
Line 133:
myCommand.ExecuteNonQuery()

I found this script from the following website
http://aspalliance.com/articleViewer.aspx?aId=138&pId=

Can anyone please help I am completely lost as to how to correct this problem.
I am using Visual Studio 2005 beta 1, IIS 6.0, .NET version 2.0.40607 and
SQL Server 2000.

Any help would be greatly appreciated.

Thank,

Devante

Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.