in reply to win32::odbc error

I think we need a little more context. How are you getting your $db reference? We need to see the call where you are getting the reference stored in $db.

Replies are listed 'Best First'.
Re^2: win32::odbc error
by tdane (Acolyte) on Dec 01, 2009 at 22:02 UTC

    Let me give you a little more. ODBC uses a "DSN" to identify the data resource to be connected to. This can be a name stored in the ODBC configuration or it can be a full ODBC connect string. There should be a line in your code that looks like this:

    $db = new Win32::ODBC("someDSN");

    or

    $db = new Win32::ODBC("Driver={SQLServer};Server=Your_Server_Name;Data +base=Your_Database_Name;Uid=Your_Username;Pwd=Your_Password;");

    And that you should check for success as well. If that call doesn't work, your $db reference won't be useful for anything.

      Hi tdane,

      my connection is successful but the query getting failed. I don't know why. If I run the smae query in sql prompt it runs fine but the same query runs through win32::odbc fails.

Re^2: win32::odbc error
by Anonymous Monk on Dec 01, 2009 at 21:59 UTC

    like below

    if (!($db = new Win32::ODBC("DSN=Book;UID=$user;PWD=$pwd;"))) { print "error message"; } else { $statement="query"; $db->Sql($statement); <continue other stuff> }

      And is that DSN defined in Control Panel->Administrative Tools->Data Sources (ODBC)?

      If it is and you can hit the "Test Data Source" button and it works, then you have exhausted my expertise. Basically, that error message looks to me like that DSN isn't working. Be careful about user issues. Is it a User DSN, a System DSN, or a File DSN?

      If the DSN works in the control panel test, your perl (as much as I have seen) should work. If it is a user DSN is your perl code running as the same user who onns the DSN specification?