At 03:05 PM 08/06/2001 +0530, [EMAIL PROTECTED] wrote:
>hi
>I am facing a problem while trying to connect toSQL Server Database
>but my code does not even trigger a request to the database ( according to
>log files)
>
>My code is below, What is the problem ?
>Is it regarding to the code ?
>Or to that of the settings made before the code is executed ( i.e copying
>of the .pm & .pll files)
>
>Thank you.
>
>#!g:/perl/bin/perl
Add a -w to your shebang line so your script emits warnings on any errors.
>require "cgi-lib.pl";
This isn't whats causing problems with your script, but you really should
be using CGI.pm instead of cgi-lib.pl. cgi-lib.pl is a vestige of the old
Perl4 days.
>use Win32::ODBC;
>
Add 'use strict' as well
>if(!($Db=new Win32::ODBC("dsn=mydsn;UID=sa;PWD= ")))
The 'new Win32::ODBC' constructor returns 'undef' on failure. Try it this
way instead:
my ($Db) = new Win32::ODBC("dsn=mydsn;UID=sa;PWD=");
if (!defined $Db) { print error stuff... }
>{
> print "Content-type: text/html\n\n";
> print "<html>";
> print "<head><title>DatabaseTest</title></head>";
> print "<body bgcolor=\"#FFFFFF\" text=\"#088000\">";
>
> print "<h2>Error Connecting to Database</h2>";
> print "<p>please try your request at a later Time</p>";
>
> print "</body></html>";
> exit;
>}
Style tip: use here-doc syntax for large blocks of quoted material:
print<<"BLOCKOFTEXT";
<html>
<head><title>DatabaseTest</title></head>
<body bgcolor="#FFFFFF" text="#088000">
<h2>Error Connecting to Database</h2>
<p>please try your request at a later Time</p>
</body></html>
BLOCKOFTEXT
This is much cleaner and easier to maintain than using multiple print
statements with escaped-quotes.
Also, as a former user of Win32::ODBC, I recommend giving DBI a try
instead, using the DBD::ODBC driver. You'll thank yourself down the road
when you need to port this code over to another DBMS. I find DBI much more
convenient to use than Win32::ODBC...though I suppose of you need to do
really complicated and funky things over ODBC, then Win32::ODBC is still
probably the better choice.
Aloha,
mel
--
mel matsuoka Hawaiian Image Productions
Chief Executive Alphageek (vox)1.808.531.5474
[EMAIL PROTECTED] (fax)1.808.526.4040
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]