Database says read-only - sql-server-2005

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.

Related

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

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

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.

SQl 2012 dead lock process by SA

Have a SQL Server 2012 with a SCCM database.
Problem I'm having is we have index errors.
Trying to run
DBCC CHECKDB (CM_KRW, REPAIR_ALLOW_DATA_LOSS)
But getting errors so I had to switch to single user.
Then I ran the command again and it finally worked after several other error messages saying multiple users were connected to the DB.
Now I need to change the DB back to Multi User:
Using:
ALTER DATABASE CM_KRW
SET MULTI_USER
But am seeing the error
Msg 1205, Level 13, State 68, Line 2
Transaction (Process ID 53) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
Msg 5069, Level 16, State 1, Line 2
ALTER DATABASE statement failed.
I ran a SQL Server Profiler trace log for deadlocks and i see lots of them all comming from SA account, for which i dont have the password and account is set to deny login.
Any ideas what I can do now?

Linked server adding user SQL Server 2012

I have recently moved a database from 2008 across to a new cluster server 2012. I am now trying to create the linked server. I have managed to add the linked server fine but when I try to add the user
EXECUTE sp_addlinkedsrvlogin
#rmtsrvname='Server',
#useself='false',
#locallogin = NULL,
#rmtuser='domain\user',
#rmtpassword='password'
This is the error it produces
Msg 33096, Level 16, State 1, Procedure sp_addlinkedsrvlogin, Line 91
A generic failure occurred during Service Master Key encryption or decryption.
Msg 15185, Level 16, State 1, Procedure sp_addlinkedsrvlogin, Line 98
There is no remote user 'domain\user' mapped to local user '(null)' from the remote server 'server'.
I have tried to backup the master service key from the 2008 database and tried to restore it, but I get the following
The current master key cannot be decrypted. If this is a database master key, you should attempt to open it in the session before performing this operation. The FORCE option can be used to ignore this error and continue the operation but the data encrypted by the old master key will be lost.
Does anyone have any ideas on why this happens?

Restoring the database.bak from local machine to the server

I am trying to restore the whole db with diagrams nd foreigns keys to the existing database on the server i want to replace that with the new one , I tried the following script with no success
drop database DuxburyCaravans
go
RESTORE DATABASE stonestore
FROM DISK = 'C:\Program Files\Microsoft SQLServer\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\DuxburyCaravans.BAK'
WITH MOVE 'DuxburyCaravans' TO 'D:\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DuxburyCaravans.mdf',
MOVE 'DuxburyCaravans_log' TO 'D:\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DuxburyCaravans.LDF'
but it comes up with errors:
Msg 3702, Level 16, State 3, Line 3
Cannot drop database "DuxburyCaravans"
because it is currently in use.
Msg 3201, Level 16, State 2, Line 1
Cannot open backup device 'C:\Program
Files\Microsoft SQL
Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\DuxburyCaravans.BAK'.
Operating system error 3(failed to
retrieve text for this error. Reason:
15105).
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating
abnormally.
The RESTORE only works on the actual server machine - is this your own PC, or is it a separate machine??
If it's a separate machine: you cannot restore a database onto a remote server from your local harddisk - you need to put the *.bak file onto a drive that the server can reach - e.g. the server's own local drives, or a network drive that the server has a mapping (and access) to.
The error states that database DuxburyCaravans is in use. You can close existing connections in SQL by changing to SINGLE_USER mode
ALTER DATABASE [DuxburyCaravans] SET SINGLE_USER With ROLLBACK IMMEDIATE
RESTORE DATABASE [DuxburyCaravans] FROM DISK = N'C:\Path\To\Backup.bak'
ALTER DATABASE [DuxburyCaravans] SET MULTI_USER
You first need to either:
Close all connections to the database you're trying to restore, or
Using MS SQL Management Studio, connect to the remote server. Right-click on the root server node and choose Activity Monitor. Expand Processes, right-click on each process that is using your database and choose Kill. Do this with caution, of course.
Now that all connections have been closed, you can restore your database.