I am trying to create a back up for an SQL Server database using command line.I have used the following command:
C:\>SqlCmd -E -S DEVE-PC3/SQLEXPRESS -Q "BACKUP DATABASE Exam_Db To Disk='d:\Exam_db.bak'"
But I am getting an error message
Msg 3201,cannot open backup device Operating System Error 5.
Msg 3013,Backup database is terminating abnormally.
What am I missing?
That error message tells you that whatever account is running the SQL Server service doesn't have permission to write to the location that you've specified. Either choose another location or give the service account permission.
Related
I am using this script to backup my SQL Server database on computer A:
sqlcmd -U MyDatabase -P MyPassword -S .\SQLEXPRESS -Q "EXEC sp_BackupDatabases #backupLocation = 'c:\shared', #databaseName='MyDatabase', #BackupType='F'"
Everything works fine, but I decided to store backup files to computer B. I shared folder on computer B, which is accessible from:
\\computerB\shared
I changed backup script to include new backup location:
sqlcmd -U MyDatabase -P MyPassword -S .\SQLEXPRESS -Q "EXEC sp_BackupDatabases #backupLocation = '\\computerB\shared', #databaseName='MyDatabase', #BackupType='F'"
But when I run this, I get this error:
Cannot open backup device '\computerB\shared\MyDatabase_FULL_101 22022_232734.BAK'. Operating system error 5 (Access denied
.).
Msg 3013, Level 16, State 1, Server WIN-C28934ASNF1\SQLEXPRESS, Line 1
BACKUP DATABASE is terminating abnormally.
I don't understand why am I getting Access denied. I can easily access \\computerB\shared from file explorer on computer A. What is wrong here?
We have to think carefully about the user account running the backup process.
When you access the \\computerB\shared location in Windows File Explorer, you use your own user account. When you run the sqlcmd script it's probably also with your own user account. However, the script is telling SQL Server to perform the backup action; it does not perform the backup directly on it's own. SQL Server is running using a different account. This different account does not have access to the shared folder.
To fix this, you can change the account used to run SQL Server, or you can let SQL Server backup locally and then copy or more the files to the share after the backup completes.
What you will probably NOT be able to do is grant SQL Server's current service account access to the shared folder, because it is most likely a special account like SYSTEM (hopefully not) or Network Service that can't be given this access.
Problem Statement:
I am trying to Load data file from Linux- source to SQL server table- target (sql server installed Windows server).
After many meetings with Microsoft we got resolve the connection issue.
Connection string:
[]$kinit windowsserverusername (Windows server AD Account) :- After this command system will prompt for password
[]$ sqlcmd -S servername,port -E -C :- After this command system will connect to sql server with ">"
BULK INSERT SQLSCHEMA.dbo.TABLENAME FROM '**/SOURCE/DataFile/INPUT_DATA.txt**' WITH (FIELDTERMINATOR=',',ROWTERMINATOR='\n');
go
And I got the following error:
Msg 4861, Level 16, State 1, Server SERVERNAME, Line 2
Cannot bulk load because the file '/SOURCE/DataFile/INPUT_DATA.txt' could not be opened. Operating system error code 3(The system cannot find the path specified.).
Issue:
Unable to use fetch the source data file path in sql statement. How to use the Linux server data file path in sql statement or in .sql file.
I have save the BULK load sql statement into .sql file and try to run the command & got same above error.
[]$ sqlcmd -S servername,port -E -C -i INPUTFILE.sql
How to use source file Linux path in sql server sql prompt or in .sql file ??
I have tried .py script by following connection string and we got trusted connection/ certificate issue and Microsoft suggested above sqlcmd method.
"pyodbc.connect('DRIVER={ODBC Driver 18 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)"
``
I have an Oracle database that is located on server_c and are only accessible if you are on server_b. So in order to connect to this Oracle database, I have to first log in to server_b via SSH, and type in the following command to connect to it.
sqlplus username/password#server_c:1571/service
I would like to connect to the Oracle database in DataGrip, first I typed in my username and password in the SSH/SSL tab.
Then I typed in the general database information.
I thought it would be fine, but when I clicked on the Test Connection, I got an error.
Error: Connection to Oracle - #server_c failed. ORA-00604: error occurred at recursive SQL level 1 ORA-20001: Server is not in the List of Valid Application Servers ORA-06512: at line 28
This error occurs if I try to connect to the database directly without logging in to server_b beforehand. In other words, I think DataGrip doesn't connect to the SSH tunnel first before connecting the database.
I'm not sure if I'm using SSH/SSL tab correctly in this way. So if you have any idea why it doesn't work or any solution to it, please let me know.
The clue is in the error message:
Error: Connection to Oracle - #server_c failed. ORA-00604: error
occurred at recursive SQL level 1 ORA-20001: Server is not in the
List of Valid Application Servers ORA-06512: at line 28
Check with your DBA either of:
a sqlnet.ora valid node checking tcp.validnode_checking = ...
or more likely:
a login trigger that prevents "unknown servers" from logging in.
We have some deployment scripts that use a combination of dacpacs through sqlpackage and straight scripts using sqlcmd.
When I execute the sqlpackage dac\sqlpackage.exe /p:BlockOnPossibleDataLoss=False /p:BackupDatabaseBeforeChanges=True /a:Publish /sf:.\somedeploy.dacpac /tcs:"Data Source=MyDB;Initial Catalog=MyCatalog;Trusted_Connection=True;"
I get an error message *** Could not deploy package. Unable to connect to target server. I have login auditing turned on in sql and the message I am getting is Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. [CLIENT: 111.222.223.224]
However, I can run our sql scripts through sqlcmd no problem by using the -E argument.
sqlcmd -i Permissions\CreateSqlUser.sql -S MyDB -E
I am running from a commandline that is set to "Run As Administrator" and am currently signed in as the admin. This is running on a Windows Server 2012 VM. I am using sql 2014. We have other installs that haven't had problems but this is our first 2014 install so we are trying to determine if something changed or if we are missing something and if so what.
If I run from profiler I don't see any audit log error messages. I checked the filters and what events I'm listening for and they all look good. Inside sql when I run exec sys.sp_readerrorlog 0, 1, 'Login Failed' I do get the messgaes to show up. (I might be doign something wrong in profiler). Also they show up in the system event logs. I'm not seeing anyplace where it tells me anything about the user attempting to login though.
If don't use trusted connection for sqlpackage and instead use a username and password it works fine. However, part of what our deployment script does is create the users so our preference would be to not do this.
I'm trying to restore a backup from a .bak file to a local database server and keep getting the error message.
An exception occurred while executing a Transact-SQL statement or batch.(Microsoft.SqlServer.ConnectionInfo)
Cannot open backup device 'C:\Clients\SQLitis\jMKZ.bak'. Operating system error 5(Access is denied.).
RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3201)
No idea where to even start troubleshooting this. I'm on an administrator account and have full privileges so there shouldn't be anything to deny me doing this but I'm still getting the error message.
Sounds like the service account that SQL Server runs under does not have permission to folder C:\Clients\SQLitis.
When SQL Server was installed, it hopefully was set up to use a domain user account (the "service account") that is NOT an administrator on the machine. As such, the SQL Server installer only grants permissions to the folders the SQL Server setup creates.
You need to give permission to that folder to the user account that SQL Server acts as. In my case it was NT Service\MSSQLSERVER
You can find/change the SQL Server user in SQL Server Configuration Manager. Here's a link that shows how:
http://www.bidn.com/blogs/ShawnHarrison/ssis/2134/access-denied-during-database-backup
Maybe a little hacky, but I solved the issue by copying the .bak file into the designated backup folder. That way I didn't have to change any permissions.