Search code examples
asp.net.netvb.netvisual-studio-2008

'instance failure' error while connection string is correct


I have following code on page load event:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        con = New SqlConnection("Data Source=14GRAFICALI\\SQLEXPRESS;Initial Catalog=sagar;Integrated Security=True")
        '-----------------------fill name ddl------------------------------'

        Try

            da = New SqlDataAdapter("select EmpName from empMaster_VB", con)
            ds = New DataSet()
            da.Fill(ds)
            For i As Integer = 0 To ds.Tables(0).Rows.Count

                ddlName.Items.Add(ds.Tables(0).Rows(i)(0).ToString())

            Next


        Catch ex As Exception

        End Try

        '--------------------------------------------------------------------'


        '----------------fill expence-------------------------------------'

        Try

            da = New SqlDataAdapter("select ExpName from expenceType_VB", con)
            ds = New DataSet()
            da.Fill(ds)
            For i As Integer = 0 To ds.Tables(0).Rows.Count

                ddlExpence.Items.Add(ds.Tables(0).Rows(i)(0).ToString())

            Next


        Catch ex As Exception

        End Try


        '---------------------------------------------------------------'



    End Sub

This code is to fill drop downs with names and expence values in database tables.

I am getting 'instance failure' error while executing the code.

I checked one of the answers on stack and checked my connection string. But, my connection string is also correct.

Please help me if anything else is missing in this code.


Solution

  • As you got the error "instance failure", that might be the error with your SQL Server instance..

    Make sure your SQL Server instance(MSSQLSERVER) is running, where you can check in: Services list. TO get into services list: open run dialog box and type: "services.msc" (without quotes) and hit Enter. That takes you to services management console, where you can check whether your instance in running or not..

    If the problem still persists, then try using: Data Source=.\SQLEXPRESS instead.. :)

    Happy Coding... :)