• SQL (A2K)

    Author
    Topic
    #448990

    I need help PLEASE!!

    I have the following code that works as it should: Keeping in mind the Uid and Pwd MUST be hard coded…..

    strConn = "Driver={SYBASE ASE ODBC Driver};NA=REPORTSNAME,4100;Uid=ME;Pwd=MYPW;database=MYDATABASE;"

    However, I want to use this code applying a variable for the “UID” and the “PWD” to avoid the HARD CODING. So let’s assume UID=ME and Pwd=MYPW:
    I want this:

    Dim myLoginID, myPass, Sql as string
    myLoginID="ME"
    myPass="MYPW"
    
    Sql = "Driver={SYBASE ASE ODBC Driver};" + "NA=REPORTSNAME,4100;" + "Uid=MyLoginID;" + "Pwd=myPass;" + "database=DATABASENAME;"

    but the connection fails because it doesn’t recognize the variables, myLoginID and myPass. I’ve been told it must be in string format (from looking at it, I thought it was, but what do I know), anyway, I tried this:

    Sql = "Driver={SYBASE ASE ODBC Driver};" + _
    Sql = "NA=REPORTSNAME,4100;" + _
    Sql = "Uid=myLoginID;" + _
    Sql = "Pwd=myPass;" + _
    Sql = "database=DATABASE;"

    but the connection fails.

    What am I not understanding or overlooking?

    Viewing 1 reply thread
    Author
    Replies
    • #1099660

      You must place the variables outside the quotes:

      Sql = "Driver={SYBASE ASE ODBC Driver};" & _
      "NA=REPORTSNAME,4100;" & _
      "Uid=" & myLoginID & ";" & _
      "Pwd=" & myPass & ";" & _
      "database=DATABASE;"

      I used & instead of +. Both will work to concatenate strings, but & is the official concatenate operator. Use of + can have unexpected results if you concatenate numeric values.

    • #1099691

      [indent]


      Dim myLoginID, myPass, Sql as string


      [/indent]
      For info – this line declares myLoginID and myPass as variants. Only Sql is typed as a string.

      Dim myLoginID as String
      Dim myPass as String
      Dim Sql as String

      will declare them all as strings.

      • #1099712

        Thanks to both of you guys. Everything works perfectly.

        Steve, thank you pointing that out my declaration issue, I wasn’t aware of that. Learning something new every day.

        Have a great day guys.

    Viewing 1 reply thread
    Reply To: SQL (A2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: