.net – Am I opening and closing the ODBC connection incorrectly

netodbcsap-asevb.net

When connecting to a Sybase ASE database via ODBC using the code below, I'll occasionally get a '[IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed' error.

Can this be caused by my code? I read here that I should be using the 'With' statement instead, but I don't understand how that would affect this.

Thanks in advance!

    Try
        odsConn.Open()
        Dim acctCheckString As String = sB.ToString
        Dim odsCmd As New OdbcCommand(acctCheckString, odsConn)

        odsRtrn = CStr(odsCmd.ExecuteScalar).TrimEnd
    Catch ex As Exception
        odsRtrn = ex.Message.ToUpper
        odsRtrn = CheckError(odsRtrn)
    Finally
        odsConn.Close()
    End Try

Best Answer

I apologize for interjecting without an answer to your specific question, but if I might make a suggestion...

In the year 2009, if you are using vb.Net, and you are still using ODBC, you should please (seriously) check out ADO.Net managed code data providers. There is one for Sybase...

SyBase ADO.Net Providers

This will completely replace the odbc libraries. they are much easier to use.

Related Topic