How to resolve "...Error occurred during the execution of xp_cmdshell"? - sql

The engineers uses this Access based app that takes data from SQL Server 2005.
The users download a file containing details of parts etc make amendments and upload it again. When the file is upload(checked-in) the information such as the modified date, userId etc is stored in SQL Server. When the user tries to check in they face this error:
The users that are working from home and use remote desktop connection to login into their account are the only one facing this error. The users that are on the office network do not get this error.
I tried making a proxy account and granting access to the user but that doesn't work.
It below query, I get the following errors:
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'GRANT'.
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'SIDNEY\UsersWindowsLoginId'.
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near 'UsersWindowsLoginId'`
Query:
CREATE LOGIN UsersWindowsLoginId
GRANT EXECUTE ON xp_cmdshell TO 'SIDNEY\UsersWindowsLoginId';
EXEC sp_xp_cmdshell_proxy_account 'UsersWindowsLoginId'
USE master;
GRANT CONTROL SERVER TO 'UsersWindowsLoginId'
GO
Also, this seems to be a recent phenomenon as the users have been working from home for a while now.
Any help is appreciated. Thanks!

First enable advanced option for run xp_cmdshell, for this need to change 1, below query to enable.Try this
USE [DatabaseName]
GO
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1;
GO
-- To update the currently configured value for advanced options.
RECONFIGURE;
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1;
GO
-- To update the currently configured value for this feature.
RECONFIGURE;
GO
Thanks and Regards
Aravind

Related

GRANT CONTROL on DATABASE::master fails

I'm logged in with the user that is marked in the Azure portal as being the server admin.
I need to grant control database to a given user so that the sys.fn_get_audit_file can be executed.
But even with the admin user I'm getting the error
Msg 262, Level 14, State 1, Line 1
CONTROL permission denied in database 'master'.
Msg 297, Level 16, State 1, Line 1
The user does not have permission to perform this action.
Any suggestions
First make sure you are using correct authentication. E.g. Windows, Azure etc.
Also be sure you have permission to create database
Run below query on you database
ALTER SERVER ROLE sysadmin ADD MEMBER your-user;
GO
Refer this link for more information.

Cannot alter procedure in SQL Server

When I run to alter the procedure, I get an error:
Msg 18487, Level 14, State 1, Line 1
Login failed for user 'tester'. Reason: The password of the account has expired.
However when I check under Security -> Logins, I can't find a user with this name.
I also tried removing the expiration with the following command:
ALTER LOGIN tester
WITH DEFAULT_DATABASE = [master],
DEFAULT_LANGUAGE = [us_english],
CHECK_EXPIRATION = OFF
The system says that the user does not exist or I don't have permission (I'm sysadmin)
Msg 15151, Level 16, State 1, Line 1
Cannot alter the login 'tester', because it does not exist or you do not have permission.
Per my comment...
Please verify that the stored procedure is not utilising a linked server which may contain/use the credentials indicated.
Stored procedures validate connections/credentials on recompile.

SQL server restore and user permission

I need to permission a user to a database right after a database restore.
I tried this:
Use [master]
go
restore database DBTest
from disk='E:\userTemp\DBTest1.bak'
WITH MOVE 'DBTest' TO 'E:\SQLData\DBTest1.mdf',
MOVE 'DBTest_log' TO 'F:\SQLData\DBTest1.ldf',
replace, recovery, stats=5, maxtransfersize=1048576
Print '---------------------------RESTORE COMPLETED ---------------------------'
-- Create the user.
CREATE USER [user_indi] FOR LOGIN [user_indi]
GO
USE [DBTest]
GO
EXEC sp_addrolemember N'db_owner', N'user_indi'
GO
When I do this, I get the following error:
Msg 15023, Level 16, State 1, Line 22
User, group, or role 'user_indi' already exists in the current database.
Msg 15410, Level 11, State 1, Procedure sp_addrolemember, Line 75
User or role 'user_indi' does not exist in this database.
So, what added the command to remove the user in the middle. Now it looks like this.
Use [master]
go
restore database DBTest
from disk='E:\userTemp\DBTest1.bak'
WITH MOVE 'DBTest' TO 'E:\SQLData\DBTest1.mdf',
MOVE 'DBTest_log' TO 'F:\SQLData\DBTest1.ldf',
replace, recovery, stats=5, maxtransfersize=1048576
Print '---------------------------RESTORE COMPLETED ---------------------------'
-- Remove the user
USE [DBTest]
GO
DROP USER [user_indi]
GO
-- Create the user.
CREATE USER [user_indi] FOR LOGIN [user_indi]
GO
USE [DBTest]
GO
EXEC sp_addrolemember N'db_owner', N'user_indi'
GO
Now, I get the error:
Msg 15151, Level 16, State 1, Line 2
Cannot drop the user 'user_indi', because it does not exist or you do not have permission.
I can't allow errors as I need to schedule this restore and permission job. Why am I getting this error and how can I workaround it?
RM
Your USE [DBTest] statements are in two different places.
In the first one, you're attempting to create the user in MASTER. In the second one, you're creating it in DBTest.

Database says read-only

I have installed SQL Server 2005 with the SQL Server Management Studio Express and tried attaching the database. The attach was successful, but the issue was next to database name it was saying read-only.
After that I tried these commands
USE [master]
GO
ALTER DATABASE [TESTDB] SET READ_WRITE WITH NO_WAIT
GO
But I got this error ,
Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file “D:\Soft\Data\Data_Data.MDF”. Operating system error 5: “5(Access is denied.)”.
Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file “D:\soft\Data\Data_Log.LDF”. Operating system error 5: “5(Access is denied.)”.
File activation failure. The physical file name “D:\Soft\Data\Data_Log.LDF” may be incorrect.
Msg 945, Level 14, State 2, Line 1
Database ‘Lis’ cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
Can you tell me what to do in order to make my database read and write?
Check that the physical files located at D:\Soft\Data\Data_Data.MDF and D:\soft\Data\Data_Log.LDF do not have the read only flag checked when you right click on them and go to properties.
If the the user Sql Server is running under does not have permissions to change the attributes for the files/folder it will not be able to un-check the box for you.

Cant drop db in single user mode?

I have tried
exec sp_dboption 'hipp_website_uat', 'single user', 'FALSE'
but i get
Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'sp_dboption'.
I have also tried setting the db to multi user in the db properties but I got
Does anyone know how I can drop this db or how to set it to multi-user mode?
I think you need to just get the users off - there is a 'Close Active Connections' option.
Have you tried checking that and then trying again ?
If you have sysadmin you can
EXEC sp_who2
and then kill the spids that are connected to the database.