locked
ODBC Connection Problem?? RRS feed

  • Question

  • User-1104215994 posted

    Hi,

    I am trying to connect to SQL Server 2008 as follows but getting "ERROR [42000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Must declare the scalar variable "@ApprovedBy"."

    How can I fix this?

    Best Regards.

    code sample:

    Dim connetionString As String
            Dim cnn As OdbcConnection
            connetionString = "Driver={SQL Server Native Client 10.0};Server=servername;
    Database=databasename;Uid=name;Pwd=pass;MTS=F;"
            cnn = New OdbcConnection(connetionString)         Dim myTransaction As OdbcTransaction = Nothing         Dim app As String = "abc"         Try             cnn.Open()             'MsgBox("Connection Open ! ")             myTransaction = cnn.BeginTransaction()             Dim comm As New Data.Odbc.OdbcCommand("UPDATE [Test]..[Test].[Test] SET ApprovedBy=@ApprovedBy,
    ApproveDate=@ApproveDate,Approved=@Approved, StatusId=@StatusId where RequestID=@RequestID"
    , cnn)             'Add to Transaction             comm.Transaction = myTransaction                        comm.Parameters.AddWithValue("@ApprovedBy", app)             comm.Parameters.AddWithValue("@ApprovalDate"Date.Now)             comm.Parameters.AddWithValue("@Approved", 1)             comm.Parameters.AddWithValue("@StatusId", 1)             comm.Parameters.AddWithValue("@RequestID", 66)             comm.ExecuteNonQuery()
    Monday, August 8, 2011 8:22 AM

Answers

  • User1992938117 posted

    I am trying to connect to SQL Server 2008 as follows but getting

    Check:

    Connection Strings

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 9, 2011 1:27 AM