Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

inserting images in ms sql server

by ahmedmc (Initiate)
on Jun 19, 2012 at 15:22 UTC ( #977097=perlquestion: print w/replies, xml ) Need Help??
ahmedmc has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to insert an image into ms sql server but I'm getting some errors while inserting it in db.

"DBD::ODBC::st execute failed: unixODBCFreeTDSSQL ServerError converting client characters into server's character set. Some character(s) could not be converted. (SQL-HY000)"

For inserting image in mysql I was able to insert it i.e. using '?' in insert statement but tried out different methods including N character to insert in ms sql but attempt was unsuccessful. Please advise at earliest to overcome this issue. Stating my query below;

my $dbh = DBI-> connect("dbi:ODBC:DSN=MSSQL;Server=$server_name;Databa +se=$db_name;UID=$db_user;PWD=$db_pass") or die "CONNECT ERROR! :: $DB +I::err $DBI::errstr $DBI::state $!\n"; my $myfile = "/home/sysadm/perl-scripts/fax-5-rx.tif"; open MYFILE, $myfile or die "Cannot open file"; my $data; # Read in the contents while (<MYFILE>) { $data .= $_; } close MYFILE; my $sql = "INSERT into tblImages(imageid,channel,pages,msgid,content) +values ('000111222','8','1','000111222',?)"; my $sth = $dbh->prepare($sql) or die("\n\nPREPARE ERROR:\n\n$DBI::err +str"); $sth->execute($data) or die("\n\nQUERY ERROR:\n\n$DBI::errstr"); $sth->finish; $dbh->disconnect;

Replies are listed 'Best First'.
Re: inserting images in ms sql server
by mje (Curate) on Jun 20, 2012 at 10:30 UTC

    What is the type of the column "content" in the table?

Re: inserting images in ms sql server
by ksublondie (Friar) on Sep 18, 2012 at 17:51 UTC
    Did you ever find a solution?

    I'm having the same problem with DBD::Sybase using the FreeTDS driver. In my research, I've found that it's an issue with FreeTDS, but I haven't been able to find a specific driver that definitively works yet.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://977097]
Approved by Corion
What's the matter? Cat got your tongue?...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2017-04-28 23:15 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (531 votes). Check out past polls.