in reply to win32::odbc/ SQL error

It really looks like the connection is failing. Also you really should error trap everything, even the execution of Sql(). On a call to new Win32::ODBC::Error() returns the last error, I don't believe $! contains the error message. Additionally it looks like your SQL had flaws. I assume the table isn't '<DATA>', so it should be written as DATA or [DATA]. Unless $machine and $LocUsr are being inserted into numeric fields you need to single quote them.

Maybe try something like this:
my $db; if(!($db = new Win32::ODBC('user_logons'))){ die 'Connect failed: ' . Win32::ODBC::Error() . "\n"; } my $sql = "INSERT INTO [Data] (pc_name, user_name,time+date) VALUES (' +$machine', '$LocUsr', GETDATE())"; if ($db->Sql($sql)) { print "Sql Error: " . $db->Error() . "\n"; print "SQL: $sql\n"; }

Replies are listed 'Best First'.
Re: Re: win32::odbc/ SQL error
by billie_t (Sexton) on May 23, 2003 at 21:34 UTC

    Thanks, everyone, for pointing out my SQL syntax errors - while working on it myself last night, I realised the problem with the table name and lack of single quotes for the variables, but it's good to get confirmation.

    As for the suggestions re the DBI module, I did consider that, but since I'm such a newbie, I thought Win32::ODBC looked "easier". I should have a look at it again in the light of this very good learning experience.

    Thanks especially tcf22 for the excellent error-checking code. I very stupidly didn't specify a username/password for the connection, so that was where it was failing - the error report pointed that out very clearly!