Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > Visual Studio 2008
|
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2009, 01:36 AM
Registered User
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Urgent - The ConnectionString property has not been initialized

I've looked at a lot of posts on different forums where others have received the same error. Most say they were not referencing the connectionstring from the web.config file correctly, or they were trying to open the connection before setting the connectionstring. Well, if that were the case for me, then how does it work on two different systems, but not on the third? It works on my development PC and on the development server, but not in the production environment. The difference is the web and DB server are separate physical servers in my production environment and on a single server for development. My setup, error message and code will be listed below.

I can simulate the error on my PC if I rename the connection string in either section of the web.config file (appsettings, connectionstrings) to something else. You will see how I have tested both below.

Any help would be GREATLY appreciated for I am in a time crunch to get some idea as to why this won't work in the production environment.

Thanks,
Jason
--------------------------------

My PC
VB.NET
XP SP3
VS 2008
SQL Server Express 2005
.NET 3.5 Framework Installed

Dev Server
Win Server 2008 Standard SP1
SQL Server 2005
.NET 3.5 Framework Installed

Prod Environment
Web Server - Win Server 2008 Standard SP1, .NET 3.5 Framework Installed
DB Server - Win Server 2008 Standard SP1, SQL Server 2005, .NET 3.5 Framework Installed

Error
Server Error in '/' Application.
--------------------------------------------------------------------------------
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 114:
Line 115: Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error
Line 116: ErrHandler.LogError(Server.GetLastError)
Line 117: End Sub
Line 118:

Source File: D:\IIS\SSIP\web\App_Code\SitePage.vb Line: 116

Stack Trace:

[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.SqlClient.SqlConnection.PermissionDema nd() +4876643
System.Data.SqlClient.SqlConnectionFactory.Permiss ionDemand(DbConnection outerConnection) +20
System.Data.ProviderBase.DbConnectionClosed.OpenCo nnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
Database.Open(String connectionstring) in C:\wwwroot\EIIASSIP\common\Core\Database.vb:47
Components.BasePage.get_DB() in C:\wwwroot\EIIASSIP\common\Core\BasePage.vb:41
Components.BasePage.get_ErrHandler() in C:\wwwroot\EIIASSIP\common\Core\BasePage.vb:49
Components.SitePage.Page_Error(Object sender, EventArgs e) in D:\IIS\SSIP\web\App_Code\SitePage.vb:116
System.Web.UI.TemplateControl.OnError(EventArgs e) +8689450
System.Web.UI.Page.HandleError(Exception e) +84
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6776
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.default_aspx.ProcessRequest(HttpContext context) +37
System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +75

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074

Code
Code:
 
 
'<!--********** web.config **********-->
<appSettings>
    <add key="ConnectionString" value="Persist Security Info=True;Initial Catalog=[database];Data Source=[server];User ID={0};Password={1};"/>
</appSettings>
 
<connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=[server];Initial Catalog=[database];Persist Security Info=True;User ID={0};Password={1};" providerName="System.Data.SqlClient"/>
</connectionStrings>
 
'********** BasePage.vb **********
Public ReadOnly Property DB() As Database
    Get
        If m_DB Is Nothing Then
            'open database connection
            m_DB = New Database
            m_DB.Open(ConnectionString) ' ********** Line 41
        End If
        Return m_DB
    End Get
End Property
 
Public ReadOnly Property ErrHandler() As ErrorHandler
    Get
        If m_ErrHandler Is Nothing Then m_ErrHandler = New ErrorHandler(DB)
        Return m_ErrHandler '**********Line 49
    End Get
End Property
 
Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
    'if using "appSettings" section for connectionstring
    ConnectionString = DBConnectionString.GetConnectionString(ConfigurationManager.AppSettings("ConnectionString"), ConfigurationManager.AppSettings("ConnectionStringUsername"), ConfigurationManager.AppSettings("ConnectionStringPassword"))
    'if using "connectionStrings" section for getting connectionstring
    'ConnectionString = DBConnectionString.GetConnectionString(ConnectionStrings.Item("ConnectionString").ConnectionString, AppSettings("ConnectionStringUsername"), AppSettings("ConnectionStringPassword"))
End Sub
 
'********** ConnectionStrings.vb **********
Public Shared Function GetConnectionString(ByVal cs, ByVal Username, ByVal Password) As String
    Dim ConnString As DBConnectionString = New DBConnectionString(cs, Username, Password)
    Return ConnString.ConnectionString
End Function
 
'********** Database.vb **********
Public Sub Open(ByVal connectionstring As String)
    RefCount = RefCount + 1
    If con Is Nothing Then
        con = New SqlConnection(connectionstring)
    End If
    If Not IsOpen() Then
        con.Open() ' ********** Line 47
    End If
End Sub
 
'********** SitePage.vb **********
 Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error
    ErrHandler.LogError(Server.GetLastError) '********** Line 116
End Sub
 
Old July 15th, 2009, 04:00 PM
Registered User
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out. I decided to look at my applicaiton pool and compare the development server with the production server. I found one difference that fixed the problem.

Both servers are using IIS7 since they are on Windows 2008 Server naturally. I went to the Advanced Settings for each application pool and noticed that "Enable 32-bit Applications" under the General section was set to False on the development server where the website works, and True on the production server where it didn't work. So I switched it to False on the production server to get it to work.
 
Old July 16th, 2009, 06:10 AM
Registered User
 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That is an odd error message to receive for that setting. I don't think Microsoft made that one very clear but i'm glad you posted the solution here.

Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
the ConnectionString Property... coolb C# 3 September 26th, 2006 02:05 AM
Connection property has not been initialized sasi.vempalli ASP.NET 1.0 and 1.1 Basics 0 September 19th, 2006 03:03 AM
ConnectionString not initialized samiboy ASP.NET 2.0 Basics 2 April 30th, 2006 06:18 AM
Connection Property:Has not been initialized louie001 ASP.NET 1.0 and 1.1 Basics 1 October 17th, 2005 11:46 PM
The ConnectionString property...! rajesh0363 All Other Wrox Books 2 July 26th, 2005 01:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.