The following runs successfully:
EXEC sys.xp_readerrorlog 0
This however does not:
SELECT *
FROM OPENROWSET(
'SQLNCLI',
'Server=.;Trusted_Connection=Yes;',
'EXEC sys.xp_readerrorlog 0')
I am logged in using my Windows account and I have sysadmin permissions on all databases on my local server, including the system databases.
Here is the error message:
Msg 7357, Level 16, State 2, Line 11
Cannot process the object "EXEC sys.xp_readerrorlog 0". The OLE DB provider "SQLNCLI10" for linked
server "(null)" indicates that either the object has no columns or the
current user does not have permissions on that object.
I've checked the folder permissions on C:\Windows\ServiceProfiles\LocalService\AppData just in case that it was an issue with OPENROWSET creating a temp file but local administrators (I'm in the group) have full control.
Why am I getting this error and how can I get around it?
Try this:
SELECT *
FROM OPENROWSET(
'SQLNCLI',
'Server=.;Trusted_Connection=Yes;',
'SET FMTONLY OFF;EXEC sys.xp_readerrorlog 0')
Basically, it's trying to infer the shape of the result before running the procedure.
Using that set option means the only way this will be possible is by executing the procedure.
Related
I'm executing a SP that dynamically builds a global temp table of data gathered from multiple databases. At the end of this SP is this line of code:
Exec msdb.dbo.sp_send_dbmail
#profile_name = #dbmailProfileName,
#recipients = #emailRecipents,
#subject = #subject,
#body = #body,
#query = 'Select * From tempdb..##MyTempTable'
This SP works perfectly when I execute it manually, however, when I let my Server Agent Job run it, it fails with the following error:
Message
Executed as user: WORKGROUP\MyServer2016$. Failed to initialize sqlcmd library with error number -2147467259. [SQLSTATE 42000] (Error 22050) Failed to initialize sqlcmd library with error number -2147467259. [SQLSTATE 42000] (Error 22050). The step failed.
Commenting out #query portion of the SP will work fine, but that's useless since I need the data emailed.
I knew it was some kind of security issue, but my lack of DBA skills defeated me here. However, I found a workaround solution which worked, not exactly what I was looking for, but it works.
Editing the Job Step to include an Execute As with my working login:
Execute As Login='MyUser'
GO
exec DBNAME.dbo.SPNAME
GO
Revert
GO
Since MyUser could run this thing manually, I executed as my login.
I was getting this same error then, after numerous trial and error attempts, another error popped up:
The EXECUTE permission was denied on the object 'xp_sysmail_format_query',
database 'mssqlsystemresource', schema 'sys'.
I added the user to the public role in the master database then added this permission for the user:
grant execute on xp_sysmail_format_query to [myuser]
It seems that Database Mail relies on this stored proc. After doing this, the email job works fine. Note: I run the job as a designated user.
Did you try use the #execute_query_database parameter? If that doesn't work, try to add the Sql Server Agent account to the Sql Server as a sysadmin
I'm working on SQL script which task is transfer binary data (images, docs) stored in SQL Database hosted on one server to shared folder on another server in the same domain. But also I want to create directory tree in this shared folder with SQL script, so I used this command with UNC path :
EXEC master.dbo.xp_create_subdir '//MYSERVER/sharedfoler/testdir/'
But I'm getting this error:
Msg 22048, Level 15, State 0, Line 0
Error executing extended stored procedure: Invalid Parameter
And my permissions are ok, becuase when I tried to transfer data to this shared folder it worked without problems. Thank you for any ideas.
you can try this:
--master.dbo.xp_create_subdir '\\MYSERVER\sharedfoler\testdir\'
--GRANT exec ON xp_cmdshell TO '<somelogin>'
EXECUTE AS LOGIN = '<other_login>';
GO
USE master;
xp_cmdshell 'md \\MYSERVER\sharedfoler\testdir\, NO_OUTPUT';
REVERT ;
'You must access this provider through a linked server.'
I'm running this batch file remotely from the database server which is also remote. I'm trying to do an export which shouldn't have a need for the linked server. When I run the query in SSMS it exports fine, but when it's executed from the batch, it gives me the error message below. I think it may be because theyre on 2 different accounts.
Here's my batch code:
SQLCMD -S dbserver -E -d dbname-i \\Network\fldr\rpt\test\script.sql
PAUSE
Here is my SQL script:
SET ANSI_NULLS ON
GO
SET ANSI_WARNINGS ON
GO
SET QUOTED_IDENTIFIER ON
GO
PRINT 'exporting data...'
INSERT INTO OPENROWSET(
'Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;
Database=\\Network\fldr\rpt\test\testdata.xls;',
'SELECT * FROM [Sheet1$]') SELECT * FROM [dbo].view_test ORDER BY [Col4]
Error message in cmd:
I solved the problem. When running the batch file form my work PC, it hits SQL Server using different account -- my Active Directory account credentials, an account which didn't exist in SSMS. I created the account and it worked.
Other steps I took prior to this (that were also needed) are the following:
1) Ran this code
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
2) Edit the registry and add the DWORD "disallowAdHocProcess" with value of "0" at this location:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.SQLADV\Providers\Microsoft.ACE.OLEDB.12.0]
"disallowAdHocProcess"=dword:00000000
3) This article: http://support.microsoft.com/kb/814398 and used ProcMon program to find the temp path I was being denied access to.
I have an OpenQuery call to Active Directory that gets the email address for a given Windows Domain account name. It works fine until I put it in an Insert trigger. The offending piece of T-SQL is:
set #sql = 'select mail from openquery(ADSI, '''
+ 'SELECT mail FROM ''''LDAP://DC=COMPANY,DC=LOCAL''''
WHERE objectClass=''''user'''' AND objectClass<>''''computer''''
AND samAccountName=''''username'''''') '
exec sp_executesql #sql, N'#recipients varchar(500) output', #recipients output
ADSI is a linked server and I have the security context set to always use a specific user account. I get the following error returned in my web app when adding a new record.
"The member with identity 'mail' does not exist in the metadata collection.
Parameter name: identity"
I have tried connecting as the same user that my app uses for connecting to the database and running the query from SQL Management Studio and I cannot replicate the problem outside of the Trigger. Can someone point me in the right direction? I suspect it is a security issue but I am lost and running out of ideas.
I've spent the past two days searching everywhere for a solution to my problem but without any luck.
I have this query that deletes record from a remote server:
delete from OPENROWSET('SQLNCLI', 'Server=AB01S\SQLEXPRESS;Database=ShopData;Trusted_Connection=yes', 'Select receipt_n,action_in, action_ty, action_field_name,action_field_type,action_field_data, terminal from tblData where receipt_n= 1 and terminal = 1');
and I am getting this error:
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".
Msg 7202, Level 11, State 1
It also suggests to use sp_addlinkedserver to add a linked server.
Some notes:
This happens only on this specific computer + remote server. On 2 different stations (Computer+Server) it worked just fine.
Insert to OpenRowSet is working OK.
Select * from OpenRowSet is working OK.
=> Changing the delete to select * works OK.
Ad hok is enabled on the computer that queries
Remote connection is enabled on the computer being queried via openrowset
I can ping the server (AB01S)
So far I have tried adding linked setup via GUI and sp_addlinkserver.
I found the problem!!
The server name (for some reason) was incorrect.
##servername returned AB01S_88
The solution was:
running the following code and then restarting the service:
exec sp_dropserver ##servername
exec sp_addserver 'AB01S', local
exec sp_serveroption 'AB01S', 'data access' , 'true'