dbmathis has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

How can I get around this? I run this same code on the Sybase drive and it works, but with ODBC / FreeTDS it fails with this error:

[Tue Jun 23 18:03:55 2009] [error] [client 10.4.3.5] DBD::ODBC::db pre +pare failed: [FreeTDS][SQL Server]Statement(s) could not be prepared. + (SQL-42000), referer: http://support.hidden.com/cgi-bin/transpose-qq +s.cgi [Tue Jun 23 18:03:55 2009] [error] [client 10.4.3.5] [FreeTDS][SQL Ser +ver]Could not find server 'DC?' in sys.servers. Verify that the corre +ct server name was specified. If necessary, execute the stored proced +ure sp_addlinkedserver to add the server to sys.servers. (SQL-42000) +at /var/www/cgi-bin/transpose-qqs.cgi line 329., referer: http://supp +ort.hidden.com/cgi-bin/transpose-qqs.cgi [Tue Jun 23 18:03:55 2009] [error] [client 10.4.3.5] Can't call method + "execute" on an undefined value at /var/www/cgi-bin/transpose-qqs.cg +i line 338., referer: http://support.hidden.com/cgi-bin/transpose-qqs +.cgi
my $db11 = "DC:server1"; my $dbor = "DC:server2"; FROM openquery([$db11], N\' SELECT r.ReqID , de.varc_EmploymentPriority , d.candidateid , d.FirstName + \'\' \'\' + d.LastName , r.sHiringManager , d.DossierType \') as hc join openquery([$dbor], N\' SELECT p.first_name , p.last_name , c.id , replace(replace(dbms_lob.substr(a.answer,4000,1),chr(10) +, \'\' \'\'),chr(13), \'\' \'\') as "Answer" , replace(replace(dbms_lob.substr(ql.question,4000,1),chr( +10), \'\' \'\'),chr(13), \'\' \'\') as "Question" , CASE ql.type

I an going to try to add the servers to the sys.server group without the colon, but is there a way I can change the code and make this work?

Replies are listed 'Best First'.
Re: Colon in server name breaks DBD::ODBC
by mje (Curate) on Jun 24, 2009 at 10:34 UTC

    I don't see how you have come to the conclusion that colons (in this case) "breaks DBD::ODBC". The error is reported by SQL Server as in:

    [FreeTDS][SQL Server]

    and the last string (on the right) in [] is the component reporting the problem.

      Ok, great, now I know it's not ODBC reporting the issue, which I suspected all along because would would DBD care was SQL Server is doing.

      Anyone know how to get around this?

        dbmathis:

        A couple suggestions:

        • It might be that the ':' in the server name could be converted to a '?' as part of the placeholder handling. If that's the case, using placeholder syntax instead of building the SQL on the fly should work nicely.
        • Perhaps SQL server doesn't like the name with a colon in it? (I've never seen a server name with a colon in it.) If that's the case, you could rename the server or create an alias for the server.
        ...roboticus