Hey guys, what am i missing here:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Using sqlConn As New SqlClient.SqlConnection(sqlConnString)
            sqlConn.Open()

            sqlConn.Close()
        End Using
    End Sub

    Public Property ServerName() As String = "myip"
    Public Property DatabaseName() As String = "mytable"
    Public Property Login() As String = "sa"
    Public Property Password() As String = "mypw"

    Public Function SqlConn(Optional timeout As Integer = 0) As String
        ' Initialize the connection string builder for the 
        ' underlying provider. 
        Dim sqlBuilder As New SqlClient.SqlConnectionStringBuilder()

        ' Set the properties for the data source. 
        sqlBuilder.DataSource = _serverName
        sqlBuilder.InitialCatalog = _databaseName
        sqlBuilder.IntegratedSecurity = False
        sqlBuilder.MultipleActiveResultSets = True 'to avoid exception if a query uses anothe rquery internal

        sqlBuilder.UserID = _Login
        sqlBuilder.Password = _Password
        If timeout > 0 Then
            sqlBuilder.ConnectTimeout = timeout
        End If

        Return sqlBuilder.ToString
    End Function

Recommended Answers

All 5 Replies

Error on Using sqlConn As New SqlClient.SqlConnection(sqlConnString) sqlConnString.

Please post you "sqlConnString" declaration code.

Its in sqlconn as you can see sqlbuilder :)

No it's not, that's what you are missing you need to declare the connection string

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.