I am trying to execute a program in Visual Studio 2005 to display the Web Interface for the Northwind Customers application using the Visual Basic Project but after I click the Start Debug button I recieve an exception below:
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 9: mConnection = New SqlConnection( _
Line 10: ConfigurationManager.AppSettings("ConnectDB"))
Line 11: mConnection.Open() Line 12: End Sub
Line 13:
Source File: C:\Documents and Settings\colemany\My Documents\Visual Studio 2005\Projects\AppDev\Applications\DataAccessLayer\DAL.vb Line:
11
Stack Trace:
[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.SqlClient.SqlConnection.PermissionDemand() +4876643
System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection) +20
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
DataAccessLayer.DALBase..ctor() in C:\Documents and Settings\colemany\My Documents\Visual Studio 2005\Projects\AppDev\Applications\DataAccessLayer\DAL.vb:11
BizObjects1.CustomerList..ctor() +43
WebUI.Northwind.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\colemany\My Documents\Visual Studio 2005\Projects\AppDev\Applications\WebUI\Northwind.aspx.vb:8
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Version Information: Microsoft .NET Framework Version:2.0.50727.3620; ASP.NET Version:2.0.50727.3618
I know I installed the Northwind database succesfully, but not sure why this error keeps hitting. I have tried googling
this, but couldn't find a solution.
My OS is Windows XP and the version for Visual Studio is Microsoft Visual Studio 2005 Team Editon for Software Developers.
I clicked the "SQL Server 2005" from connectionstrings.com and it gave me a bunch of different types of security codes but I assume I use the one below:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
How ever is this code suppose to be placed in web.config file? Here is what is currently in this file now:
It still didn't work when I changed the authentication mode node to "Forms".
To add more detail to this issue, the error is hitting the code mConnection.Open from the Data Access Layer vb file I created that is shown below.
Imports System.Configuration
Imports System.Data.SqlClient
Public MustInherit Class DALBase
Private mConnection As SqlConnection
#Region " Constructors and Destructors "
Protected Sub New()
mConnection = New SqlConnection( _
ConfigurationManager.AppSettings("ConnectDB"))
mConnection.Open()
End Sub
Protected Sub New(ByVal sConnect As String)
mConnection = New SqlConnection(sConnect)
mConnection.Open()
End Sub
Public Sub Dispose()
mConnection.Close()
mConnection.Dispose()
End Sub
#End Region
#Region " Object properties "
Protected ReadOnly Property Connection() _
As SqlConnection
Get
Return mConnection
End Get
End Property
Protected ReadOnly Property ConnectionString() _
As String
Get
Return mConnection.ConnectionString
End Get
End Property
#End Region
End Class
I get an error when I entered the code you suggested. Was this code suppose to be within this file I've sent you?
I placed the new code here:
Protected Sub New(ByVal sConnect As String)
mConnection = New SqlConnection(sConnect)
mConnection.Open()
If mConnection.Open() Then MsgBox("Connections is OPEN") End If
End Sub
Maybe I placed it in the wrong place??
By the way, I appreciate you taking the time to help me with this.
ycoleman82
Member
33 Points
18 Posts
The ConnectionString property has not been initialized.
Jul 14, 2011 03:31 PM|LINK
Hello,
I am trying to execute a program in Visual Studio 2005 to display the Web Interface for the Northwind Customers application using the Visual Basic Project but after I click the Start Debug button I recieve an exception below:
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 9: mConnection = New SqlConnection( _ Line 10: ConfigurationManager.AppSettings("ConnectDB")) Line 11: mConnection.Open() Line 12: End Sub Line 13:Source File: C:\Documents and Settings\colemany\My Documents\Visual Studio 2005\Projects\AppDev\Applications\DataAccessLayer\DAL.vb Line: 11
Stack Trace:
Version Information: Microsoft .NET Framework Version:2.0.50727.3620; ASP.NET Version:2.0.50727.3618
I know I installed the Northwind database succesfully, but not sure why this error keeps hitting. I have tried googling this, but couldn't find a solution.
My OS is Windows XP and the version for Visual Studio is Microsoft Visual Studio 2005 Team Editon for Software Developers.
Thanks,
Yontine
march11
Contributor
3005 Points
1364 Posts
Re: The ConnectionString property has not been initialized.
Jul 14, 2011 04:04 PM|LINK
Try this site for hte connection type you are using.
http://connectionstrings.com/
ycoleman82
Member
33 Points
18 Posts
Re: The ConnectionString property has not been initialized.
Jul 14, 2011 04:49 PM|LINK
I clicked the "SQL Server 2005" from connectionstrings.com and it gave me a bunch of different types of security codes but I assume I use the one below:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
How ever is this code suppose to be placed in web.config file? Here is what is currently in this file now:
<?xml version="1.0"?>
<configuration>
<appSettings>
<connectionStrings>
<add name="ConnectDB"
connectionString="Data Source=localhost\sqlexpress;Initial Catalog=mydatabase;User Id=myuser;Password=mypassword;"
/>
</
connectionStrings
>
<
system.web
>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
Visual Basic options:
Set strict="true" to disallow all data type conversions
where data loss can occur.
Set explicit="true" to force declaration of all variables.
-->
<
compilation debug="true" strict="true" explicit="true"
/>
<
pages
>
<
namespaces
>
<
clear
/>
<
add namespace="System"
/>
<
add namespace="System.Collections" />
<
add namespace="System.Collections.Specialized" />
<
add namespace="System.Configuration" />
<
add namespace="System.Text" />
<
add namespace="System.Text.RegularExpressions" />
<
add namespace="System.Web" />
<
add namespace="System.Web.Caching" />
<
add namespace="System.Web.SessionState"
/>
<
add namespace="System.Web.Security"
/>
<
add namespace="System.Web.Profile"
/>
<
add namespace="System.Web.UI"
/>
<
add namespace="System.Web.UI.WebControls"
/>
<
add namespace="System.Web.UI.WebControls.WebParts"
/>
<
add namespace="System.Web.UI.HtmlControls"
/>
</
namespaces
>
</
pages
>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<
authentication mode="Windows"
/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</
system.web
>
</
configuration
>
march11
Contributor
3005 Points
1364 Posts
Re: The ConnectionString property has not been initialized.
Jul 14, 2011 05:43 PM|LINK
Should work.
Are you using windows or forms authentication?
march11
Contributor
3005 Points
1364 Posts
Re: The ConnectionString property has not been initialized.
Jul 14, 2011 05:44 PM|LINK
I see your copied code says windows, I am not sure if Northwind will need windows, my guess is that it will use forms though.
ycoleman82
Member
33 Points
18 Posts
Re: The ConnectionString property has not been initialized.
Jul 14, 2011 06:02 PM|LINK
Should I change the <authentication mode> node to equal "forms" in web.config?
Also in the connection string, was I suppose to put in my actual username and password within the connection string nodes?
<connectionStrings>
<add name="ConnectDB"
connectionString="Data Source=localhost\sqlexpress;Initial Catalog=mydatabase;User Id=myuser;Password=mypassword;" />
</connectionStrings>
march11
Contributor
3005 Points
1364 Posts
Re: The ConnectionString property has not been initialized.
Jul 14, 2011 08:21 PM|LINK
try both, if neither works leave it on forms and lets look to other issues.
ycoleman82
Member
33 Points
18 Posts
Re: The ConnectionString property has not been initialized.
Jul 15, 2011 01:51 PM|LINK
It still didn't work when I changed the authentication mode node to "Forms".
To add more detail to this issue, the error is hitting the code mConnection.Open from the Data Access Layer vb file I created that is shown below.
Imports System.Configuration Imports System.Data.SqlClient Public MustInherit Class DALBase Private mConnection As SqlConnection #Region " Constructors and Destructors " Protected Sub New() mConnection = New SqlConnection( _ ConfigurationManager.AppSettings("ConnectDB")) mConnection.Open()End Sub Protected Sub New(ByVal sConnect As String) mConnection = New SqlConnection(sConnect) mConnection.Open() End Sub Public Sub Dispose() mConnection.Close() mConnection.Dispose() End Sub #End Region #Region " Object properties " Protected ReadOnly Property Connection() _ As SqlConnection Get Return mConnection End Get End Property Protected ReadOnly Property ConnectionString() _ As String Get Return mConnection.ConnectionString End Get End Property #End Region End Classmarch11
Contributor
3005 Points
1364 Posts
Re: The ConnectionString property has not been initialized.
Jul 15, 2011 02:06 PM|LINK
Try something like this.
If Conenction.Open() Then
msgbox("Connections is OPEN")
Endif
you'll at least know that it is open and can run queries against it.
ycoleman82
Member
33 Points
18 Posts
Re: The ConnectionString property has not been initialized.
Jul 15, 2011 02:34 PM|LINK
I get an error when I entered the code you suggested. Was this code suppose to be within this file I've sent you?
I placed the new code here:
Protected Sub New(ByVal sConnect As String) mConnection = New SqlConnection(sConnect) mConnection.Open() If mConnection.Open() Then MsgBox("Connections is OPEN") End If End SubMaybe I placed it in the wrong place??
By the way, I appreciate you taking the time to help me with this.