Urgent - The ConnectionString property has not been initialized
-
Tuesday, July 14, 2009 10:09 PM
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 InstalledDev Server
Win Server 2008 Standard SP1
SQL Server 2005
.NET 3.5 Framework InstalledProd 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 InstalledError
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. If I can somehow debug while on the production box, maybe I could figure it out. Not sure though.
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.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
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(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.default_aspx.ProcessRequest(HttpContext context) +37
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074
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
All Replies
-
Wednesday, July 15, 2009 8:01 PM
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.

