I have searched the threads for this but nothing seems to answer my questions. I am doing a tutorial
I am getting the error :
The ConnectionString property has not been initialized.
[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.SqlClient.SqlConnection.Open() +433
jokepoint.Catalog.GetDepartments() in C:\MyCommerceSite\JokePoint\BusinessObjects\Catalog.vb:11
jokepoint.DepartmentsList.Page_Load(Object sender, EventArgs e) in C:\MyCommerceSite\JokePoint\UserControls\DepartmentsList.ascx.vb:31
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Page.ProcessRequestMain() +750
Here are the relevant docs.
web.config
<?xmlversion="1.0"encoding="utf-8"?>
<configuration>
<appSettings>
<addkey="ConnectionString"value="data source=sql3.webcontrolcenter.com; Initial Catalog=dbname;User ID=*******;Password=*******"/>
</appSettings>
<system.web>
<customErrorsmode="Off"/>
<globalizationrequestEncoding="utf-8"responseEncoding="utf-8"/>
</system.web>
</configuration>
Catalog.vb
Imports System.Data.SqlClient
PublicClass Catalog
PublicSharedFunction GetDepartments()As SqlDataReader
' Create the connection object
Dim connectionAsNew SqlConnection("ConnectionString")
' Create and initialize the command object
Dim commandAsNew SqlCommand("GetDepartments", connection)
command.CommandType = CommandType.StoredProcedure
' Open the connection
connection.Open()
' Return a SqlDataReader to the calling function
Return command.ExecuteReader(CommandBehavior.CloseConnection)
EndFunction
PrivateSharedReadOnlyProperty connectionString()AsString
Get
Return ConfigurationSettings.AppSettings("ConnectionString")
EndGet
EndProperty
EndClass
Anyone have any ideas?
Yea- first of all, you are using way way too much excess code...Try completely removing this:
PrivateSharedReadOnlyProperty connectionString()AsString
Get
Return ConfigurationSettings.AppSettings("ConnectionString")
EndGet
EndProperty
EndClass
And replacing this:
' Create the connection object
Dim connectionAsNew SqlConnection("ConnectionString")
With this:
' Create the connection object
Dim connectionAsNew SqlConnection( ConfigurationSettings.AppSettings("ConnectionString") )
And you should be just fine...
OK Here is the new document. No change. Ideas?
Imports System.Data.SqlClient
PublicClass Catalog
PublicSharedFunction GetDepartments()As SqlDataReader
' Create the connection object
Dim connectionAsNew SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
' Create and initialize the command object
Dim commandAsNew SqlCommand("GetDepartments", connection)
command.CommandType = CommandType.StoredProcedure
' Open the connection
connection.Open()
' Return a SqlDataReader to the calling function
Return command.ExecuteReader(CommandBehavior.CloseConnection)
EndFunction
EndClass
Hi there,
Are you still getting any error messages ??
If yes, can you post the exact error message
Cheers!
You can see the error yourself here
http://209.200.112.194/default.aspx
Here is a cut and paste
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:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|
Did you import System.Configuration ?
And what code do you have in your Page_Load?
Here is the situation. I am following a book, "Beginning ASP.NET 1.1 E-Commerce. The book has me working on a local SQL server. I am working remotly and trying to make the changes needed to do it that way.
Instead of posting code I will post a txt version of the docs.
This contains the code for the connection
http://209.200.112.194/txtdocs/catalog.vb.txt
This is a user control code behind
http://209.200.112.194/txtdocs/departmentslist.ascx.vb.txt
this is the user control - view source to see the code
http://209.200.112.194/txtdocs/departmentslist.ascx.txt
web config
http://209.200.112.194/txtdocs/web.config.txt
Help?
Laura K
yea, it's just like I thought. you have to Import System.Configuration into the filehttp://209.200.112.194/txtdocs/catalog.vb.txt
Imports.system.configuration
didn't work
Thats because if you wrote it like that, you didnt write it correctly
In that file the 1st line is:
Imports System.Data.SqlClient
And you just need to add the 2nd line here...
Imports System.Data.SqlClient
Imports System.Configuration
I wrote it correctly in my doc.
Didn't work!
post all of your code in the page that is getting the error so we can see what might be wrong...
LKnomad wrote:
Dim connectionAsNew SqlConnection("ConnectionString")
' Create and initialize the command object
Dim commandAsNew SqlCommand("GetDepartments", connection)
command.CommandType = CommandType.StoredProcedure
' Open the connection
connection.Open()
' Return a SqlDataReader to the calling function
Return command.ExecuteReader(CommandBehavior.CloseConnection)
EndFunctionPrivateSharedReadOnlyProperty connectionString()AsString
Get
Return ConfigurationSettings.AppSettings("ConnectionString")
EndGet
EndProperty
EndClass
Hi,
personally I think you don't access your property the way you coded it.
Try changing this line:
Dim connectionAsNew SqlConnection("ConnectionString")
with this one:
Dim connectionAsNew SqlConnection(connectionString)
Also take a look at this tutorial:Store Your Database Connection String in Web.Config...
Grz, Kris.
The page that is getting the error is the default.aspx page. This page contains a dynamic user control which I believe is the culprit because when I remove this control the page loads. The user control has an ascx and an ascx.vb. I have also posted them. Lastly there is one more doc which has the connection info.
The default page is on the root.
The user control docs are in a folder called UserControls
The doc with the connection info is in a folder called businessObjects.
The web config is on the root.
Here are links to txt files of all the code. Easier to read this way.
Below is the doc in the businessObjects folder containing all the connection info. Notice I have added the imports as suggested.
http://209.200.112.194/txtdocs/catalog.vb.txt
The two docs in the UserControl folder.
http://209.200.112.194/txtdocs/departmentslist.ascx.txt (view source for the full code)
http://209.200.112.194/txtdocs/departmentslist.ascx.vb.txt
Here are the docs on the root. This first doc is the default doc where I am getting the error.
http://209.200.112.194/txtdocs/default.aspx.txt
http://209.200.112.194/txtdocs/default.aspx.vb.txt (code behind)
http://209.200.112.194/txtdocs/web.config.txt (web.config)
I have emailed the author of this tutorial to see if he will offer any support as well.
Thanks
Laura K
Tried the change earlier and tried again just now.
No luck.
Thanks
Laura
0 comments:
Post a Comment