I've got a SQL Server 2008 that needs to connect to a POSTGRESQL 9.0 server.
One of the tasks that i need is to get the next value of a sequence over the POSTGRESQL
Example 1 :
execute ('select nextval( ''cadastro.pessoa_seq'' )' ) at POSTGRESQL ;
error:
Msg 7215, Level 17, State 1, Line 1 Could not execute statement on
remote server 'POSTGRESQL'.*
Example 2 :
select * from openquery( POSTGRESQL ,'select nextval( ''cadastro.pessoa_seq'' )')
error:
Msg 7399, Level 16, State 1, Line 1 The OLE DB provider "MSDASQL" for
linked server "POSTGRESQL" reported an error. The provider reported an
unexpected catastrophic failure. Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider "MSDASQL" for
linked server "POSTGRESQL".*
None of these options works!
Is there any good alternative ?
Thank you in advance
dealing with ODBC sources and postgres I have to do this:
nextval(''cadastro.pessoa_seq''::regclass) for it to work
Perhaps your Postgresql connection is readonly , have you tried to execute an update/insert request ?
nextval update the sequence , try:
currval(''cadastro.pessoa_seq''::regclass)
Related
I am transferring the data from the local SQL server to a remote (PostgreSQL) table using a Linked server (ODBC). This works perfectly as long as I stick with Select query but fails with Insert, Delete, etc.
Error :
OLE DB provider "MSDASQL" for linked server "DDL_PUYAML1_64" returned
message "the driver cound't identify inserted rows". Msg 7343, Level
16, State 2, Line 75 The OLE DB provider "MSDASQL" for linked server
"DDL_PUYAML1_64" could not INSERT INTO table "[MSDASQL]".
I have tried with Single Value but nothing changes.
As suggested Error messages when you perform an UPDATE, INSERT, or DELETE Transact-SQL statement on a remote table by using the OpenQuery function: "7357" and "7320" here, I have tried with column names instead of "*" and tried putting where 1=0 as well.
Any suggestion/feedback is appreciated.
Thank you!
EDIT: PFB the code
Insert openquery([DDL_PUYAML1_64],'select sn1,encl,encl_model from ws_sls_core.dd_enclosures_forarsdashboard_v1 where 1=0 ')
select sn1,encl,encl_model from #temp1
I have a Windows 2019 machine. I have SQL Server 2016. I have created a linked server & I am trying to execute some queries on a remote Db2 server. I am using MSDASQL provider, i.e. 'Microsoft OLE DB Provider for ODBC Drivers'.
The INSERT & SELECT queries work fine.
However the UPDATE & DELETE queries fail. For example, a DELETE query as shown gives the below error.
DELETE OPENQUERY (TEST2016, 'SELECT * FROM ABC.WORK_ITEM WHERE id = 123');
Msg 7399, Level 16, State 1, Line 12.
The OLE DB provider "MSDASQL" for linked server "TEST2016" reported an error. The provider did not give any information about the error.
Msg 7320, Level 16, State 2, Line 12.
Cannot execute the query "SELECT * FROM ABC.WORK_ITEM WHERE id = 123" against OLE DB provider "MSDASQL" for linked server "TEST2016".
As I mentioned, if I run the SELECT query separately, as shown below, the query works fine.
select * from OPENQUERY(TEST2016, 'SELECT * FROM ABC.WORK_ITEM where wi_id = 123');
Am I missing any configuration/settings?
My problem is when I run the bulk insert it return the following error. Any idea on the error? Some help is appreciated.
Actually regarding this issues my testing environment able to execute normally but my production server return this error.
Error message:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
Code:
BULK INSERT Table_ZZ
FROM 'e:\Folder\sometextfile.txt'
WITH
(ROWTERMINATOR = '')
Check that the CSV fields are correct, the error could be due to number of columns in the DB not matching the CSV pattern (newly created columns or whatever).
In addition to this, i suggest you to consider the newline character as the row terminator, using its ASCII code:
(ROWTERMINATOR = '0x0A')
Hope this helps.
Updating SQL Patches solve my problem.
Before the SQL server are not yet being patches, one day decide to do patches, and suddenly solve my problem.
I am trying to read from a CSV file located on shared folder on the network but getting error for the following code:
SELECT * INTO #TempTbl
FROM OPENROWSET
('SQLNCLI11',
'ServerName = <username>;Trusted_Connection=yes;',
'Driver={Microsoft Text Driver (*.txt; *.csv)};
DefaultDir=\\sharedpath\DIR path\;
SELECT * FROM CSV_File.csv) as Test
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near ','.
When I remove the server line like this:
SELECT * INTO #TempTbl
FROM OPENROWSET
('SQLNCLI11',
--'ServerName = <username>';Trusted_Connection=yes;',
'Driver={Microsoft Text Driver (*.txt; *.csv)};
DefaultDir=\\sharedpath\DIR path\;
SELECT * FROM CSV_File.csv) as Test
I get the following error:
OLE DB provider "SQLNCLI11" for linked server "(null)" returned message "Invalid authorization specification".
OLE DB provider "SQLNCLI11" for linked server "(null)" returned message "Invalid connection string attribute".
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI11" for linked server "(null)" reported an error. Authentication failed.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "SQLNCLI11" for linked server "(null)".
What does that mean? Does this error message indicate something wrong in my script or is access permission issue? I was able to read from a table on the server suing the same openrowset connection when I no longer use the CSV driver.
I am not sure what to do in order to get this openrowset to read the CSV file. Any clue? Do you think it has to do with the server account does not have access to the account I am using does not have access to the shared folder?
You are using the wrong provider. Your connection string is written for connecting to a server (sort of). You should be using the bulk option for OPENROWSET per example E on this page.
It would look something like this, although you need to create a format file per the instructions here.
SELECT *
FROM OPENROWSET( BULK '\\sharedpath\DIR path\CSV_File.csv',
FORMATFILE = '\\sharedpath\DIR path\CSV_format.fmt');
I am trying to do a query via ODBC to our ERP database. The documentation guide suggests that we use OPENQUERY to send the query.
Here is my example query
SELECT
Q.Part_No,
Q.[Description],
Q.Part_Type
FROM OPENQUERY
(
LINKEDSERVER,
'
SELECT
P.Part_No,
P.[Description],
P.Part_Type
FROM LINKEDSERVER...Part_V_Part AS P
WHERE P.Part_No = ''2712768''
'
) AS Q
When I try to run that query though I get the following error
OLE DB provider "MSDASQL" for linked server "LINKEDSERVER" returned message "[LINKED][ODBC Plex ODBC Report Data Source driver][OpenAccess SDK SQL Engine]Syntax error in SQL statement. syntax error line 1 at or after token <LINKEDSERVER>.[0]".
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "
SELECT
P.Part_No,
P.[Description],
P.Part_Type
FROM LINKEDSERVER...Part_V_Part AS P
WHERE P.Part_No = '2712768'
" for execution against OLE DB provider "MSDASQL" for linked server "LINKEDSERVER".
Can anyone help me here? I've never used OPENQUERY before, but I'm coping the example straight as it is in the example documentation.
Should be like this
SELECT
Q.Part_No,
Q.[Description],
Q.Part_Type
FROM OPENQUERY
(
LINKEDSERVER,
'
SELECT
P.Part_No,
P.[Description],
P.Part_Type
FROM DatabaseName.SchemaName.Part_V_Part AS P
WHERE P.Part_No = ''2712768''
'
) AS Q
Replace DatabaseName and SchemaName with your actual database name and schemaname (probably dbo)
You don't need the linked server name inside the query
Take a look at Having Fun With OPENQUERY And Update,Delete And Insert Statements for some examples