locked
Connection String property has not been initialized. RRS feed

  • Question

  • I have a web application that  works perfectly on my local machine but not once Ive uploaded to the hosting server i get:

    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 423:            Dim conn As New SqlConnection(connstring)
    Line 424:            conn.Open()
    Line 425:            SqlCon.Open()
    Line 426:
    Line 427:            Try

    Source File: C:\inetpub\wwwroot\bancounico\usercontrols\form_Recrutamento.vb    Line: 425

    Stack Trace:
    [InvalidOperationException: The ConnectionString property has not been initialized.]
       System.Data.SqlClient.SqlConnection.PermissionDemand() +5038498
       System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection) +20
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
       System.Data.SqlClient.SqlConnection.Open() +125
       usercontrols_form_Recrutamento.btnSubmeter6_Click(Object sender, EventArgs e) in C:\inetpub\wwwroot\bancounico\usercontrols\form_Recrutamento.vb:425
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
    


    below is the part of the .vb
    If txtNome.Text <> String.Empty Then
           Dim connstring As String = "Data Source=10.2.24.29;Persist Security Info=True;User ID=sa;Password=Pr0dUn1C0$qL;database=BdCves"
           Dim conn As New SqlConnection(connstring)
           conn.Open()
           SqlCon.Open()
           Dim intrans As SqlClient.SqlTransaction = conn.BeginTransaction
           Try
             Dim Cmd As SqlCommand = Nothing
             Dim InsStr As String = " INSERT INTO candidato (data_hora,nome,apelido,rua_avenida,cidade_distrito,codigo_postal,pais,telefone,telemovel,fax,email, nacionalidade,data_nascimento,sexo,ano_conclusao,nivel_academico, instituicao_academica, area_interesse, prov_interesse, comp_profissionais, comp_informaticas, comp_tecnicas, outras_competencias, categoria_carta, possui_experiencia, provincia, estado,sessao_id) VALUES ('" & Now & "','" & Me.txtNome.Text & "','" & Me.txtApelido.Text & "','" & Me.txtRuaAv.Text & "','" & Me.txtCidadeDistrito.Text & "','" & Me.txtPostal.Text & "','" & Me.txtPais.Text & "','" & Me.txtTelefone.Text & "','" & Me.txtTelemovel.Text & "','" & Me.txtFax.Text & "','" & Me.txtMail.Text & " ','" & Me.txtNac.Text & "','" & CDate(txtDataNas.Text) & "','" & Me.DropDownList1.SelectedValue & "','" & Me.txtAnoConclusao.Text & "','" & Me.DropDownNivelAcademico.SelectedValue & "','" & Me.txtInstEnsino.Text & "','" & Me.DropDownAreaInteresse.SelectedValue & "','" & Me.DropDownProvInteresse.SelectedValue & "','" & Me.txtCompProf.Text & "','" & Me.txtCompInfo.Text & "','" & Me.txtCompTecn.Text & "','" & Me.txtAptidoes.Text & "','" & Me.txtCarta.Text & "','" & Me.DropDownExp.SelectedValue & "' ,'" & Me.DropDownProvInteresse.SelectedValue & "','" & Me.txtEstado.Text & "','" & txtSessionID.Text & "')"
             Cmd = New SqlCommand(InsStr)
             Cmd.Transaction = intrans
             Cmd.Connection = conn
             Cmd.ExecuteNonQuery()
     
             intrans.Commit()
             lblmsg.Text = "A simulação foi gravada com sucesso com o nome " & txtNome.Text & "."
           Catch ex As Exception
             lblMessage.Text = ex.Message
             intrans.Rollback()
           Finally
             SqlCon.Close()
             conn.Close()
           End Try
         End If

    Thanks in advance....
    Friday, May 11, 2012 3:57 PM

Answers

  • ok but in the above code there is no sqlcon declaration as sqlconnection

    you declare conn as sqlconnection variable and you added that connectionstring to it

    if in your code you declare sqlcon as new sqlconnection then check your connection string

    the error

    The ConnectionString property has not been initialized.

    will comes maximum when the connection string is wrong so at that time your application not able to connect that database

    so please check your code and connection string

    • Proposed as answer by Mark Liu-lxf Monday, May 14, 2012 3:05 AM
    • Marked as answer by Mark Liu-lxf Tuesday, May 22, 2012 7:53 AM
    Saturday, May 12, 2012 11:45 AM

All replies

  • The correct forums for asp.net are:

    http://www.asp.net please mark this as answered and move your discussion to asp.net unless it relates to a vb.net class outside of the asp.net webpage.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/

    • Proposed as answer by The Thinker Friday, May 11, 2012 5:01 PM
    • Unproposed as answer by RichadAbdul Saturday, May 12, 2012 11:16 AM
    Friday, May 11, 2012 5:01 PM
  • Hi,

    what is sqlcon, means it is another connection string

    where you declared it and its connection string

    Friday, May 11, 2012 5:06 PM
  • Hi kumar the sqlcon is the the connection string and its declared in the beginig of the code
    Saturday, May 12, 2012 11:16 AM
  • ok but in the above code there is no sqlcon declaration as sqlconnection

    you declare conn as sqlconnection variable and you added that connectionstring to it

    if in your code you declare sqlcon as new sqlconnection then check your connection string

    the error

    The ConnectionString property has not been initialized.

    will comes maximum when the connection string is wrong so at that time your application not able to connect that database

    so please check your code and connection string

    • Proposed as answer by Mark Liu-lxf Monday, May 14, 2012 3:05 AM
    • Marked as answer by Mark Liu-lxf Tuesday, May 22, 2012 7:53 AM
    Saturday, May 12, 2012 11:45 AM