I try to do a across database query in AZURE SQL elastic pools but it's not working.
My stored procedure is:
CREATE PROCEDURE [dbo].[CreateNewSurveyQuestion]
#QuestionString varchar(MAX)
AS
INSERT INTO CTRL_Survey(SurveyQuestion)
VALUES (#QuestionString)
--create new survey in new qm
EXEC sp_execute_remote
N'QCentralDS',
N'INSERT INTO [dbo].[SurveyTbl]([Question], [IsActive], [CreateDate])
VALUES(#QuestionStringValue, 1, GETDATE())'
, N'#QuestionStringValue varchar(300)'
, #QuestionStringValue = #QuestionString
EXEC stored procedure [not working with error message below]
EXEC [dbo].[CreateNewSurveyQuestion]
#QuestionString = N'Add a new question'
Error message:
Msg 64, Level 20, State 0, Line 1
A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)
I am sure all EXTERNAL DATA SOURCE are correct. And I can run this part in my SQL Server Management Studio successfully.
EXEC sp_execute_remote
N'QCentralDS',
N'INSERT INTO [dbo].[SurveyTbl]([Question], [IsActive], [CreateDate])
VALUES(#QuestionStringValue, 1, GETDATE())'
, N'#QuestionStringValue varchar(300)'
, #QuestionStringValue = #QuestionString
Is there any issue with this mode of work, or exists another way to do it?
Related
I get an error from one of my databases when trying to execute this one
create or alter procedure [dbo].[test_sp]
with execute as owner
as
SELECT SUSER_SNAME()+ ' '+ USER_NAME();
begin
exec master..sp_trace_generateevent #eventid = 82 ,
#userinfo=N'test'
end
GO
exec [dbo].[test_sp]
Error:
Msg 8189, Level 14, State 10, Procedure master..sp_trace_generateevent, Line 1 [Batch Start Line 9]
You do not have permission to run 'SP_TRACE_GENERATEEVENT'.
Granted ALTER TRACE to my user (which returns in SUSER_SNAME()), but it wasn't help
The same script on the second database (same server) works without errors.
What else can it be?
You're trying to run this with EXECUTE AS OWNER, and the owner is a database-level principal and you can't operate outside the current database while impersonating a database-level principal. Switch to EXECUTE AS CALLER (the default) to have the caller's identity used to run the proc in master. eg
create or alter procedure [dbo].[test_sp]
with execute as caller
as
SELECT SUSER_SNAME()+ ' '+ USER_NAME();
begin
exec master..sp_trace_generateevent #eventid = 82, #userinfo = N'test'
end
GO
exec [dbo].[test_sp]
This can be made to work with owner-impersonation by marking the database as TRUSTWORTHY. See: Extending Database Impersonation by Using EXECUTE AS and Guidelines for using the TRUSTWORTHY database setting in SQL Server
Looking for pointers on how to resolve this issue.
I have a linked server setup.
This query works in SSMS, I get rows back.
SELECT tbl.[Col1]
,tbl.[CoL2]
FROM [LINKEDSERVER].[CATALOG].[SCHEMA].[TABLENAME] tbl
But trying to do the same in SSMS with OPENQUERY fails
SELECT [Col1]
FROM OPENQUERY([LINKEDSERVER],
'SELECT tbl.[Col1]
,tbl.[CoL2]
FROM [LINKEDSERVER].[CATALOG].[SCHEMA].[TABLENAME] tbl'
) As Whatever
The messages are as follows:
OLE DB provider "SQLNCLI11" for linked server "SERVER" returned
message "Deferred prepare could not be completed.". Msg 8180, Level
16, State 1, Line 1 Statement(s) could not be prepared. Msg 7202,
Level 11, State 2, Line 1 Could not find server 'SERVER' in
sys.servers. Verify that the correct server name was specified. If
necessary, execute the stored procedure sp_addlinkedserver to add the
server to sys.servers.
The server name SERVER does appear when I check select * from sys.servers
OPENQUERY from here against other linked servers is successful.
Because when you use OPENQUERY you send the query you want to run on the remote server. The error is being thrown by the remote server. Take out the linked server name in the query. Something along these lines.
SELECT [Col1]
FROM OPENQUERY([LINKEDSERVER],
'SELECT tbl.[Col1]
,tbl.[CoL2]
FROM [CATALOG].[SCHEMA].[TABLENAME] tbl'
) As Whatever
This sentence its use with another server but , its ok try this:
EXEC SP_SERVEROPTION 'SERVER\INSTANCIA' ,'DATA ACCESS',TRUE
SELECT * FROM OPENQUERY(YOURSERVER,'SELECT * FROM TABLE').
And its done. :)
I'm working on SQL Server 2008 and I'm trying to execute a stored procedure which updates a table and executes another stored procedure on a linked server.
The point is it works when no update is made, just like this:
[test_DTC] on [Server1]
CREATE PROCEDURE [dbo].[test_DTC]
#UserId int,
#Status tinyint
AS
BEGIN
EXEC [Server2].[Database].[dbo].[test_DTC];
END
GO
[test_DTC] on [Server2]
CREATE PROCEDURE [dbo].[test_DTC]
AS
BEGIN
PRINT 'Done'
END
GO
Execute on Server1:
EXEC [test_DTC]
Result:
Done
But when I include the UPDATE on Server1 procedure, it fails.
[test_DTC] on [Server1]
CREATE PROCEDURE [dbo].[test_DTC]
#UserId int,
#Status tinyint
AS
BEGIN
UPDATE
Users
SET
Status=#Status
WHERE
UserId=#UserId;
EXEC [Server2].[Database].[dbo].[test_DTC];
END
GO
[test_DTC] on [Server2]
CREATE PROCEDURE [dbo].[test_DTC]
AS
BEGIN
PRINT 'Done'
END
GO
Execute on Server1:
EXEC [test_DTC]
Result
Provider OLE DB "SQLNCLI10" from linked server "[Server2]" returned message "The transaction has already been implicitly or explicitly committed". Msg 7391, Level16, State 2, Procedure [Server2].[Database].[dbo].[test_DTC], Line 19
The operation could not be performed because OLE DB provider "SQLNCLI10" for linked server "Server2" was unable to begin a distributed transaction.
Thanks for your help
I have found a solution for this is the MSDN Blog
it says
The reason is that when transactions propagate from one machine to another they include their machine name/DNS name along with it. When it arrives on the other machine, it will use this name to attempt to communicate back to the originator machine. If this communication fails then distributed transactions will not work in the system.
Microsoft has provided a Detailed Article on the same
I am getting below error message when I am trying to run stored procedure.
Msg 7399, Level 16, State 1, Procedure accountupdater, Line 10 The OLE
DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)"
reported an error. Access denied. Msg 7350, Level 16, State 2,
Procedure accountupdater, Line 10 Cannot get the column information
from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server
"(null)".
Additional information: previously it was working, but after installing MS Office it start to give an error message. We uninstalled MS Office and reinstalled “Microsoft Access Database Engine 2010”. Still getting error message.
Did some research and found that I need to install “Microsoft Access Database Engine 2010”. I did, but still getting the same error message.
ALTER PROCEDURE [dbo].[accountupdater]
AS
DECLARE #accountNum numeric, #businessFEIN varchar(100), #stateID varchar(100), #dbaName varchar(100), #addressLine1 varchar(100), #addressLine2 varchar(100), #city varchar(100), #state varchar(100), #zip varchar(100), #businessName varchar(100)
DECLARE accountCursor CURSOR FAST_FORWARD FOR
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Text; HDR=YES; Database=D:\Innoprise\',
'SELECT * FROM flagstaffAccountUpdate.csv') ors
OPEN accountCursor
--perform first fetch
FETCH NEXT FROM accountCursor INTO #accountNum, #businessFEIN, #stateID, #dbaName, #addressLine1, #addressLine2, #city, #state, #zip, #businessName
--check if there are more rows to fetch
WHILE ##FETCH_STATUS = 0
BEGIN
update BUSINESS SET FEIN=coalesce(#businessFEIN, FEIN), name=coalesce(#businessName, name) WHERE ID = (select business_id from VENDOR v where v.vendornumber=#accountNum);
update DBA set name=coalesce(#dbaName, name) where id = (select primarydba_id from vendor v where v.vendorNumber=#accountNum);
update VENDOR set stateId=coalesce(#stateID, stateID) where vendorNumber=#accountNum;
update ADDRESS set addressLine1=coalesce(#addressLine1,addressLine1), ADDressline2=coalesce(#addressLine2,addressline2),
city=coalesce(#city,city), state=coalesce(#state,state), zipCode=coalesce(#zip,zipCode)
where ID = (select v.address_ID from VENDOR v where v.vendorNumber = #accountNum);
FETCH NEXT FROM accountCursor INTO #accountNum, #businessFEIN, #stateID, #dbaName, #addressLine1, #addressLine2, #city, #state, #zip, #businessName
END
CLOSE accountCursor
DEALLOCATE accountCursor
If you have installed Microsoft Access Database Engine 2010 already,then please execute following queries and restart SQL Server Management Studio or SQL Services.
Refer here
USE [master]
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
GO
i use sql server 2008 for publisher and sql server 2005 express for subscriber ,
when i insert to a table from my subscriber this error occur :
Msg 21079, Level 16, State 1, Procedure sp_getpublisherlink, Line 52
The RPC security information for the Publisher is missing or invalid. Use sp_link_publication to specify it.
Msg 20512, Level 16, State 1, Procedure sp_MSreplraiserror, Line 8
Updateable Subscriptions: Rolling back transaction.
Msg 3609, Level 16, State 1, Line 1
The transaction ended in the trigger. The batch has been aborted.
when insert to table from publisher all thing is ok .
Try creating the link on the subscriber. Run this on your subscriber database.
sp_link_publication #publisher = '{publisher instance name}'
, #publisher_db = '{published database name}'
, #publication = '{publication name}'
, #security_mode = '1'
, #login = '{sql server login account to connect publisher}'
, #password = '{password}'
, #distributor = '{distributor instance name}'