Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 March 14th, 2005, 10:05 AM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default The ConnectionString property has not been initial

[font=Verdana]hi, I am very new at asp and I'm having trouble with making a connection to my database my web config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
     <customErrors mode="Off" />
     <compilation debug="true"/>
  </system.web>
  <appSettings>
    <add key="NWind"
         value="server=(local)\NetSDK; database=Northwind; integrated security=SSPI" />
    <add key="myWinds"
         value="Provider=Microsoft.Jet.OleDb.4.0; data source=C:\BegASPNETdb\webroot\datasources\theWinds .mdb;" />
    <add key="sWinds"
         value="Provider=Microsoft.Jet.OleDb.4.0; data source=C:\BegASPNETdb\webroot\datasources\theWinds .mdb;" />
    <add key="Asset"
         value="Provider=Microsoft.Jet.OleDb.4.0; data source=C:\BegASPNETdb\webroot\datasources\Assets.m db;" />
<add key="Assets"
         value="server=(local)\NetSDK; database=Assets; integrated security=SSPI" />
  </appSettings>
</configuration>

I am trying to connect to my Assets database to populate a dropdown box that code looks like this:

<script runat="server">
sub page_load(source as object, e as eventargs)
    if not ispostback then
        dim strConnection as string
            strConnection=configurationSettings.Appsettings("A ssets")
        dim objConnection as new sqlConnection()
        dim strSQL as string
        dim objCommand as new sqlCommand()
            strSQL = "Select EqTypeID, EqType From EQType"
            with objCommand
            .commandText=strSql
            .Connection=objconnection
            end with
        objconnection.open()
            cboEquipment.datasource = objCommand.ExecuteReader()
            cboEquipment.DataTextField="EqType"
            cboEquipment.DataValueField="EqTypeID"
            cboEquipment.DataBind()
        objConnection.close()
    end if
end sub
</script>

The problem comes in when I try and run it I get this 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 19: .Connection=objconnection
Line 20: end with
Line 21: objconnection.open()
Line 22: cboEquipment.datasource = objCommand.ExecuteReader()
Line 23: cboEquipment.DataTextField="EqType"


Source File: C:\BegASPNETdb\webroot\hw2.aspx Line: 21

Stack Trace:


[InvalidOperationException: The ConnectionString property has not been initialized.]
   System.Data.SqlClient.SqlConnection.Open() +433
   ASP.HW2_aspx.page_load(Object source, EventArgs e) in C:\BegASPNETdb\webroot\hw2.aspx:21
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731

Like I said I am very new at this and I'm getting myself very confused. I have tried everything that I can think of and am having no luck. any help would be great.


 
Old March 14th, 2005, 01:30 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

 Try: dim objConnection as new sqlConnection(strConnection)

 
Old March 14th, 2005, 08:35 PM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks I changed my code to look like this:

<script runat="server">
sub page_load(source as object, e as eventargs)
    if not ispostback then
        dim strconnection as string = ConfigurationSettings.AppSettings("Asset")
        dim objconnection as new sqlconnection(strconnection)
        objconnection.open()
        dim strSQL as string
        strSQL = "Select EqTypeID, EqType From EQType"
        dim objCommand as new sqlCommand(strSQL, objconnection)

            with objCommand
            .commandText=strSql
            .Connection=objconnection
            end with
        objconnection.open()
            cboEquipment.datasource = objCommand.ExecuteReader()
            cboEquipment.DataTextField="EqType"
            cboEquipment.DataValueField="EqTypeID"
            cboEquipment.DataBind()
        objConnection.close()
    end if
end sub


but now I get this error:

Cannot open database requested in login 'Assets'. Login fails. Login failed for user 'Machinename\ASPNET'

any sugguestions, I thought I've given all the permissions that I know to do.


 
Old March 15th, 2005, 01:54 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I believe the ASPNET account needs to be set up on your SQL Server.
 
Old October 31st, 2006, 03:02 AM
Authorized User
 
Join Date: Aug 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Byock
Default

Help!

I am havin this error...........what was causing it? How can i solve this? Please help...thanks



***************

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:


[InvalidOperationException: The ConnectionString property has not been initialized.]
   System.Data.SqlClient.SqlConnection.Open() +433
   Office.Inquiry.Page_Load(Object sender, EventArgs e) in C:\Inetpub\Office\Inquiry.aspx.vb:85
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750




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


*****************

I have the following codes in my page_load codes....

Dim ddSqlConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C ol_Conn"))
ddSqlConnection.Open()

*********************

And this is my web.config codes


<appSettings>
    <add key="myConn" value="server=servername;user=username;password=pa ssword;database=office;"/>
</appSettings>



 
Old October 31st, 2006, 04:25 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

libbydoo and Byock, I too went around and around with this also, so I understand the frustration and being new makes it even more frustrating. I even had help from this forum. The problem is it is not finding the database.

Byock: your statment, configurations.appsettings should read "myConn" instead of what you have,"Col_Conn" the key in web.config must match exactly.

libbydoo: Your usage of the appsettings is correct, however be aware
of how you continue/continuation of a line.

What chapter are you on, try and use just one database reference first.... this is a suggestion. I used the example in the book, before using this feature in production. My sample I used came out of the ASP.NET Databases using VB.NET, Chapter 3, pp.91-92. Better still download the code and look at chapter 3, SQLServer_connection_2.aspx (still uses the northwind sql db).

The final point is: make sure you have the web.config in the correct place. I have two pc's, one a desktop and the a laptop and the web.config file reside in different directories and this is the KEY, just dont give up on the example until it works in your environment.

So on that note, I will put my "soap box" away. I beleive the name of my topic was :Web.Config..working or not working...or something like that...

Hope this helps and good luck...
 
Old November 22nd, 2006, 10:11 PM
Registered User
 
Join Date: Nov 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by libbydoo
 [font=Verdana]hi, I am very new at asp and I'm having trouble with making a connection to my database my web config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
     <customErrors mode="Off" />
     <compilation debug="true"/>
</system.web>
<appSettings>
    <add key="NWind"
         value="server=(local)\NetSDK; database=Northwind; integrated security=SSPI" />
    <add key="myWinds"
         value="Provider=Microsoft.Jet.OleDb.4.0; data source=C:\BegASPNETdb\webroot\datasources\theWinds .mdb;" />
    <add key="sWinds"
         value="Provider=Microsoft.Jet.OleDb.4.0; data source=C:\BegASPNETdb\webroot\datasources\theWinds .mdb;" />
    <add key="Asset"
         value="Provider=Microsoft.Jet.OleDb.4.0; data source=C:\BegASPNETdb\webroot\datasources\Assets.m db;" />
<add key="Assets"
         value="server=(local)\NetSDK; database=Assets; integrated security=SSPI" />
</appSettings>
</configuration>

I am trying to connect to my Assets database to populate a dropdown box that code looks like this:

<script runat="server">
sub page_load(source as object, e as eventargs)
    if not ispostback then
        dim strConnection as string
            strConnection=configurationSettings.Appsettings("A ssets")
        dim objConnection as new sqlConnection()
        dim strSQL as string
        dim objCommand as new sqlCommand()
            strSQL = "Select EqTypeID, EqType From EQType"
            with objCommand
            .commandText=strSql
            .Connection=objconnection
            end with
        objconnection.open()
            cboEquipment.datasource = objCommand.ExecuteReader()
            cboEquipment.DataTextField="EqType"
            cboEquipment.DataValueField="EqTypeID"
            cboEquipment.DataBind()
        objConnection.close()
    end if
end sub
</script>

The problem comes in when I try and run it I get this 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 19: .Connection=objconnection
Line 20: end with
Line 21: objconnection.open()
Line 22: cboEquipment.datasource = objCommand.ExecuteReader()
Line 23: cboEquipment.DataTextField="EqType"


Source File: C:\BegASPNETdb\webroot\hw2.aspx Line: 21

Stack Trace:


[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.SqlClient.SqlConnection.Open() +433
ASP.HW2_aspx.page_load(Object source, EventArgs e) in C:\BegASPNETdb\webroot\hw2.aspx:21
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731

Like I said I am very new at this and I'm getting myself very confused. I have tried everything that I can think of and am having no luck. any help would be great.




The beginning of your problem id NetSDK is not a user

     <add key="NWind"
value="server=(local)\NetSDK; database=Northwind; integrated security=SSPI" />


Check out!

p2p.Wrox forums: http://p2p.wrox.com/topic.asp?TOPIC_ID=37898 which will explain the soulution for your problem.


If your using SQL Server 2000 here is the fix I used with additional information. The code works for me although because my installation of SQL server 2000 was as the default the connection string used was modified to

<appSettings>
    <add key="ConnectionString" value="server=(local);database=Bid;Trusted_Conne ction=true" />
</appSettings>

http://forums.microsoft.com/MSDN/sho...36684&siteid=1





icon_snowman





Similar Threads
Thread Thread Starter Forum Replies Last Post
the ConnectionString Property... coolb C# 3 September 26th, 2006 02:05 AM
The ConnectionString property has not been initial mar0364 ASP.NET 1.0 and 1.1 Basics 6 March 17th, 2006 11:24 PM
The ConnectionString property...! rajesh0363 All Other Wrox Books 2 July 26th, 2005 01:55 PM
Re-Initial variable to zero akibaMaila VB.NET 2002/2003 Basics 3 July 12th, 2005 01:41 PM
Initial Apache setup fahrionm BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 June 7th, 2004 03:02 PM





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