If you can you should stick to the ODBC driver under the DBI as much as possible. Otherwise I would recommend that you use the Win32::OLE module and create recordsets to the database.
The OLE method should only be a fall back position (though it can't always be helped) as your function calls are no longer DBI based. Hence this affects your portability.
Two examples of OLE code can be found in the following:
Or heres snippet from some recent code I have been using. This code selects information from a Memo field.
use constant DATA => 'driver=Microsoft Access Driver (*.mdb);
+dbq=data.mdb';
my $db_connection = new Win32::OLE('ADODB.Connection');
my $rs = new Win32::OLE("ADODB.Recordset");
# Connect to the database and tie the recordset object to
# the database.
$db_connection->Open(DATA);
# Set the connection doohickey
# $rs->CursorLocation(adUseClient);
my $sql = "select c.info from MYTABLE as c;";
$rs->Open($sql, $db_connection, adOpenKeySet);
if($rs->BOF())
{
return;
}
my $data = $rs->getrows();
return unless defined($data->[0][0]);
return $data->[0][0];
Ok thats with access but it should be the same for MSSQL
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.