The ConnectionString property has not been initialized.

Discussion in 'ASP .Net' started by Laura K, May 8, 2005.

  1. Laura K

    Laura K Guest

    Tried all kinds of things. I get the error.

    The ConnectionString property has not been initialized.



    Any help appreciated.

    -----------------------------------------------------------------------------------------------------
    This is the web.config info

    <configuration>

    <appSettings>

    <add key="connectionstring" value="Data Source=path to database;
    database=testingsite;User Id=UserID;Password=password" />

    </appSettings>

    -------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Here is the doc mentioned in the error.



    Imports System.Data.SqlClient



    Public Class Catalog

    Public Shared Function GetDepartments() As SqlDataReader

    ' Create the connection object

    Dim connection As New SqlConnection(connectionString)

    ' Create and initialize the command object

    Dim command As New SqlCommand("dbo.GetDepartments", connection)

    command.CommandType = CommandType.StoredProcedure

    ' Open the connection

    connection.Open()

    ' Return a SqlDataReader to the calling function

    Return command.ExecuteReader(CommandBehavior.CloseConnection)

    End Function

    Private Shared ReadOnly Property connectionString() As String

    Get

    Return ConfigurationSettings.AppSettings("ConnectionString")

    End Get

    End Property

    End Class
     
    Laura K, May 8, 2005
    #1
    1. Advertising

  2. Laura K wrote:
    > Tried all kinds of things. I get the error.
    >
    > The ConnectionString property has not been initialized.
    >
    >
    >
    > Any help appreciated.
    >
    > -----------------------------------------------------------------------------------------------------
    > This is the web.config info
    >
    > <configuration>
    >
    > <appSettings>
    >
    > <add key="connectionstring" value="Data Source=path to database;
    > database=testingsite;User Id=UserID;Password=password" />
    >
    > </appSettings>
    >
    > -------------------------------------------------------------------------------------------------------------------------------------------------------------------
    >
    > Here is the doc mentioned in the error.
    >
    >
    >
    > Imports System.Data.SqlClient
    >
    >
    >
    > Public Class Catalog
    >
    > Public Shared Function GetDepartments() As SqlDataReader
    >
    > ' Create the connection object
    >
    > Dim connection As New SqlConnection(connectionString)
    >
    > ' Create and initialize the command object
    >
    > Dim command As New SqlCommand("dbo.GetDepartments", connection)
    >
    > command.CommandType = CommandType.StoredProcedure
    >
    > ' Open the connection
    >
    > connection.Open()
    >
    > ' Return a SqlDataReader to the calling function
    >
    > Return command.ExecuteReader(CommandBehavior.CloseConnection)
    >
    > End Function
    >
    > Private Shared ReadOnly Property connectionString() As String
    >
    > Get
    >
    > Return ConfigurationSettings.AppSettings("ConnectionString")
    >
    > End Get
    >
    > End Property
    >
    > End Class
    >
    >


    I know the tags are case-sensitive in web.config. Can't remember about
    the keys/vals values. Try changing the case sensitivity of your
    ..AppSettings call or the key name in the config (make them the same).

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
     
    Craig Deelsnyder, May 8, 2005
    #2
    1. Advertising

  3. Laura K

    Laura K Guest

    I tried dozen of case changes. That doesn't seem to be it.

    Any other ideas?


    "Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
    news:...
    > Laura K wrote:
    >> Tried all kinds of things. I get the error.
    >>
    >> The ConnectionString property has not been initialized.
    >>
    >>
    >>
    >> Any help appreciated.
    >>
    >> -----------------------------------------------------------------------------------------------------
    >> This is the web.config info
    >>
    >> <configuration>
    >>
    >> <appSettings>
    >>
    >> <add key="connectionstring" value="Data Source=path to database;
    >> database=testingsite;User Id=UserID;Password=password" />
    >>
    >> </appSettings>
    >>
    >> -------------------------------------------------------------------------------------------------------------------------------------------------------------------
    >>
    >> Here is the doc mentioned in the error.
    >>
    >>
    >>
    >> Imports System.Data.SqlClient
    >>
    >>
    >>
    >> Public Class Catalog
    >>
    >> Public Shared Function GetDepartments() As SqlDataReader
    >>
    >> ' Create the connection object
    >>
    >> Dim connection As New SqlConnection(connectionString)
    >>
    >> ' Create and initialize the command object
    >>
    >> Dim command As New SqlCommand("dbo.GetDepartments", connection)
    >>
    >> command.CommandType = CommandType.StoredProcedure
    >>
    >> ' Open the connection
    >>
    >> connection.Open()
    >>
    >> ' Return a SqlDataReader to the calling function
    >>
    >> Return command.ExecuteReader(CommandBehavior.CloseConnection)
    >>
    >> End Function
    >>
    >> Private Shared ReadOnly Property connectionString() As String
    >>
    >> Get
    >>
    >> Return ConfigurationSettings.AppSettings("ConnectionString")
    >>
    >> End Get
    >>
    >> End Property
    >>
    >> End Class
    >>
    >>

    >
    > I know the tags are case-sensitive in web.config. Can't remember about
    > the keys/vals values. Try changing the case sensitivity of your
    > .AppSettings call or the key name in the config (make them the same).
    >
    > --
    > Craig Deelsnyder
    > Microsoft MVP - ASP/ASP.NET
     
    Laura K, May 8, 2005
    #3
  4. Try this:-
    <add key="ConnectionString" value="Data Source=(local);
    database=Northwind; Integrated Security=SSPI" />

    MAKE SURE U ARE PASSING THE CORRECT KEY IN UR APPLICATION.

    Patrick



    *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrick Olurotimi Ige, May 8, 2005
    #4
  5. Laura K

    Brock Allen Guest

    > <add key="connectionstring" value="Data Source=path to database;
    > database=testingsite;User Id=UserID;Password=password" />


    When this says "path to database", what exactly is the value you're specifying?
    It should be "servername" or "servername\instance".

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen
     
    Brock Allen, May 8, 2005
    #5
  6. Patrick Olurotimi Ige wrote:
    > Try this:-
    > <add key="ConnectionString" value="Data Source=(local);
    > database=Northwind; Integrated Security=SSPI" />
    >
    > MAKE SURE U ARE PASSING THE CORRECT KEY IN UR APPLICATION.
    >
    > Patrick
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***


    Heh, I blew right past that part :) Obviously that's pry the problem...

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
     
    Craig Deelsnyder, May 8, 2005
    #6
  7. Laura K

    Laura K Guest

    When I say path to database it is remote.

    sql3.webcontrolcenter.com


    "Brock Allen" <> wrote in message
    news:...
    >> <add key="connectionstring" value="Data Source=path to database;
    >> database=testingsite;User Id=UserID;Password=password" />

    >
    > When this says "path to database", what exactly is the value you're
    > specifying? It should be "servername" or "servername\instance".
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    >
     
    Laura K, May 8, 2005
    #7
  8. Brock good u figured out that issue ..
    And Laura have u finally fixed the connection?
    Patrick


    *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrick Olurotimi Ige, May 9, 2005
    #8
  9. Laura K

    Laura K Guest

    Nope connection not fixed. I am also posting this on another forum. Here
    is a list of docs. would love to have help. I am totally lost on this one.

    Here is the exact same thing as I posted on the other forum. Any help
    appreciated.

    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

    "Patrick Olurotimi Ige" <> wrote in message
    news:Otxjw$...
    > Brock good u figured out that issue ..
    > And Laura have u finally fixed the connection?
    > Patrick
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
     
    Laura K, May 9, 2005
    #9
  10. Laura maybe you can give a try like this:-
    Don't use:-
    ConfigurationSettings.AppSettings("ConnectionString")

    Try including your connectionstring in ur code like:-

    Dim connection As New SqlConnection("Data Source=SERVERNAME;Initial
    Catalog=YOURDATABASE;User Id=sa;Password=asdasd;")

    Hope that helps
    ** See how it goes**

    Patrick




    *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrick Olurotimi Ige, May 10, 2005
    #10
  11. Laura K

    Laura K Guest

    "Patrick Olurotimi Ige" <> wrote in message
    news:%23c%...
    > Laura maybe you can give a try like this:-
    > Don't use:-
    > ConfigurationSettings.AppSettings("ConnectionString")
    >
    > Try including your connectionstring in ur code like:-
    >
    > Dim connection As New SqlConnection("Data Source=SERVERNAME;Initial
    > Catalog=YOURDATABASE;User Id=sa;Password=asdasd;")
    >
    > Hope that helps
    > ** See how it goes**
    >
    > Patrick
    >
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
     
    Laura K, May 10, 2005
    #11
  12. Laura K

    athir13en

    Joined:
    Oct 5, 2007
    Messages:
    1
    it work... but how if i stil wanna use connection string at web config?
     
    athir13en, Oct 5, 2007
    #12
  13. Laura K

    brenk

    Joined:
    May 15, 2010
    Messages:
    1
    novice need help

    excuse me..
    i saw a problem like that one..
    and i have followed patrick's way..but it seems doesn't work for me..

    but this message appear..
    "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections."

    can some one help me??
    thank's..
     
    brenk, May 15, 2010
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MattB
    Replies:
    3
    Views:
    54,790
    nada111
    Oct 4, 2007
  2. CJM
    Replies:
    2
    Views:
    4,522
  3. Kent Johnson

    ConnectionString not initialized..?

    Kent Johnson, Oct 1, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    4,632
    Juan T. Llibre
    Oct 2, 2005
  4. RAM
    Replies:
    0
    Views:
    589
  5. Antoni Massó Mola
    Replies:
    1
    Views:
    451
    Michelle Hlaing
    Feb 24, 2005
Loading...

Share This Page