Friday, April 25. 2008Setting up PostgreSQL as a Linked Server in Microsoft SQL Server 64-bitPrinter FriendlyRecommended Books: SQL Server 2008 Management and Administration Expert SQL Server Integration Services
Comments
Display comments as
(Linear | Threaded)
Hi. I am actually having trouble making a linked server to Postgres even with the 32-bit server. It all seems to work (and I can use the same ODBC driver easily to import the PostgreSQL data to Microsoft Access), but when I try to query a short simple table, I get this kind of message:
select StoreCode, Date, ActualBanked from Postgres.rmsweb.[public].Banking returns OLE DB provider "MSDASQL" for linked server "Postgres" returned message "ERROR: syntax error at or near ""Col1004""; Error while executing the query". Msg 7320, Level 16, State 2, Line 1 Cannot execute the query "SELECT "Tbl1002"."StoreCode" "Col1004","Tbl1002"."Date" "Col1005","Tbl1002"."ActualBanked" "Col1007" FROM "rmsweb"."public"."Banking" "Tbl1002"" against OLE DB provider "MSDASQL" for linked server "Postgres". (it seems to be doing some kind of a column and table name translation and getting confused) Any thoughts? thanks Mark Lockett
Hello,
I had the same problem and I found the solution and post it to my Blog here: http://blog.danielcosta.pt/?p=492 Hope this help! Daniel Costa
Thanks for the report. We'll need to try this out ourselves and report on it. we'll try to do this in our August/September 2009 issue.
I have a similiar problem on 32 bit. Can you please help?
Regards Wolfgang I used (32 bit version): SELECT PID, value FROM OPENQUERY(PGCounter, 'SELECT * from "PostGreDB".originalTable ') worked somehow (i can see data in a MSSQL Server Management Express View). If i use SELECT PID, value FROM OPENQUERY(PGCounter, 'SELECT PID, value from "PostGreDB".originalTable ') the error is OLE DB provider "MSDASQL" for linked server "PostGreDB" returned message "ERROR: column "PID" does not exist; No query has been executed with that handle". Msg 7350, Level 16, State 2, Procedure containerload2, Line 3 Cannot get the column information from OLE DB provider "MSDASQL" for linked server "PostGreDB". Additionally i cannot insert data --------------------------- Microsoft SQL Server Management Studio Express --------------------------- No row was updated. The data in row 1 was not committed. Error Source: .Net SqlClient Data Provider. Error Message: The operation could not be performed because OLE DB provider "MSDASQL" for linked server "PostGreDB" was unable to begin a distributed transaction. OLE DB provider "MSDASQL" for linked server "PostGreDB" returned message "MSDTC XARMCreate error". Correct the errors and retry or press ESC to cancel the change(s). --------------------------- OK Help ---------------------------
Wolfgang,
Save yourself some hassle and don't use mixed or upper case field/table names in PostgreSQL. Change them to all lowercase. If you use upper case letters then, you need to quote the field names as well as what you are currently doing with the table name. In your example since PID is not quoted -- it will be looking for a field called "pid" and not "PID"
Hello.
Your article is very Worthy. I still have the following trouble: 1. I can not see the tables of Postgres in the Object Explorer. The following messages pops up: Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "NNMSERVERLINKED". (Microsoft SQL Server, Error: 7303) - I have done: Running the driver, creating the DSN successfully. Thanks in advanced for your soon reply!
You verified you have the right user name and password and other settings. The error as I recall is not terribly helpful and always gives that error if any part is wrong.
After I created the DSN, with the download from http://code.google.com/p/visionmap/downloads/detail?name=setup_psqlODBC_x64_8.3.4.0.exe&can=2&q=
I had to modify the T-SQL. Had to add a datasource name (@datasrc='PostgreSQL35W') EXEC master.dbo.sp_addlinkedserver @server = N'NAMEOFLINKEDSERVERHERE', @srvproduct=N'PostgreSQL35W', @datasrc='PostgreSQL35W', @provider=N'MSDASQL', @provstr=N'Driver=PostgreSQL 64-bit ODBC Drivers;uid=pgUser;Server=pgHostIP;database=pgDatabase;pwd=pgUserPassword' /* For security reasons the linked server remote logins password is changed with ######## */ EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'NAMEOFLINKEDSERVERHERE', @useself=N'True',@locallogin=NULL,@rmtuser=NULL,@rmtpassword=NULL
I downloaded and installed every link on the page, where the heck is the psqlodbcwAMD64.reg file? I cannot find it anywhere therefore cannot run it
Google turns up empty, and the site that things link to is some Japanese site that you can no longer download the driver Someone please help!
Serge,
Haven't tried the new 64-bit driver yet, but on the psqlodbc site, there is now a 64-bit ODBC driver. Give that one a try http://www.postgresql.org/ftp/odbc/versions/msi/ Its the one called: psqlodbc_09_00_0101-x64.zip http://wwwmaster.postgresql.org/download/mirrors-ftp/odbc/versions/msi/psqlodbc_09_00_0101-x64.zip
A few questions..
1. Step 2: Can you provide me a list of the .dll filenames to ensure i am using the correct one? 2. Step 3: I have the same problem as Serge above. I downloaded and installed the ..._0100_1-x64.zip package and am still unable to find the psqlodbcwAMD64.reg file. Thank you in advance!
Craig,
The .reg file was packaged with the experimental dll we were using when we wrote this article (quite a while ago). The ODBC drivers that are on the PostgreSQL site don't need the registration since they do it as part of the MSI install process. Read our newer article on this: http://www.postgresonline.com/journal/archives/196-SQL-Server-64-bit-Linked-Server-woes.html The names of the drivers have changed over the years, so hesitant to give out a name since I think I'm running an older version so might be misleading. I think the article we have listed above has the newer driver name to reference
Linked Server fails from SQL Server 2008 R2 and PostgreSQL
Please let me know the solution for following error!! I created a SYSTEM DSN (ODBC) onto PostgreSQL Server from Windows Server 2008 (64-bit) on which the SQL Server 2008 R2. Then I created a Linked Server by using the SQL Server management studio GUI, and the test connection was succeeded. I can see all table names of PostgreSQL on the SQL Server management studio GUI, however, if I try to generate a SQL script, the following error occurs. -------------------------------------------------------------------------------- Enumerate columns failed for LinkedServer 'POSTGRESQL35W'. (Microsoft.SqlServer.Smo) An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) Cannot get the data of the row from the OLE DB provider "SQL Server" for linked server "(null)". Conversion failed because the data value overflowed the data type used by the provider. (Microsoft SQL Server, Error: 7346) -------------------------------------------------------------------------------- Also, if I try to use OpenQuery; select * from openquery([POSTGRESQL35W],'select * from public.t_event'); the following error occurs. -------------------------------------------------------------------------------- The OLE DB provider "MSDASQL" for linked server "POSTGRESQL35W" reported an error. The provider reported an unexpected catastrophic failure. Cannot get the column information from OLE DB provider "MSDASQL" for linked server "POSTGRESQL35W". --------------------------------------------------------------------------------
I think there are some data types that don't translate well via the driver. For those I usually have to case them as part of the sql statement.
To see if that is the issue, try selecting a couple of columns that are simple like just varchar and integer.
Amy,
forgot about something try using MSDASQL.1 instead refer to this: http://www.postgresonline.com/journal/archives/196-SQL-Server-64-bit-Linked-Server-woes.html
Hi All I am stuck with a problem. I want to access MS Sql remotely from postgres (on my local m/c) which is installed on Solaris 10 i386. This is to retrieve some of the columns from a table.
|
Entry's LinksQuicksearchCalendar
Categories
Blog Administration |
This article is a bit of a companion to our article on Setting up PostgreSQL as a Linked Server in Microsoft SQL Server 64-bit In this article we shall demonstrate using Microsoft SQL Server 2005/2008 OPENQUERY AND OPENROWSET to add, delete and update
Tracked: Feb 19, 12:33
Tracked: Jul 23, 13:37
Tracked: Feb 21, 19:02
Tracked: Apr 15, 16:43