Agmp
Agmp

Reputation: 1

Problems with DataAdapter at VB.Net in a connection to SQL Server 2008

I´m experimenting troubles on a local connection to SQL Server 2008, it´s throwing me the next especific error: A network-related or instance-specific error ocurred while establishing a connection to SQL Server. The server was not found or was not accesible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections (error 40) I´ve tried with most of solutions concerning to SQL Services and Firewall Solutions, so i think the problem is specific in the source code, so it is:

Private Sub cargar_Combo(ByVal ComboBox As ComboBox, ByVal sql As String)
Dim strConexion As String = "Data Source=Angel-PC\SQLEXPRESS1;Initial Catalog=sistemaReferencias;Integrated Security=True"
    Dim conexion As New SqlConnection(strConexion)
    Try
       conexion.Open()
        Dim cmd As New SqlCommand(sql, conexion)
        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet
        da.Fill(ds)
        ComboBox.DataSource = ds.Tables(0)
        ComboBox.DisplayMember = ds.Tables(0).Columns(1).Caption.ToString
        ComboBox.ValueMember = ds.Tables(0).Columns(0).Caption
    Catch ex As Exception
        MessageBox.Show(ex.Message.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
        If conexion.State = ConnectionState.Open Then
            conexion.Close()
        End If
    End Try
End Sub

I know that the String connection is right, because i used it in another method, the error comes specifically at the "da.Fill(ds)" line, those are the basics I really appreciate any help you can provide.

Upvotes: 1

Views: 754

Answers (1)

Jim
Jim

Reputation: 962

Go to your desktop. Right click and add a new text file, "test.txt". Rename the text file to test.udl, you will get a warning, just accept it. Double click test.udl, and you will have an interactive dialog to configure your connection string.

Once you have configured the connection string. Click save. The right click the test.udl file and open in notepad. This will give you the connection string that you need to put into your app.

Upvotes: 1

Related Questions