SQL Server 2008 Deploy app - sql-server

I created the database on SQL Server 2008 and connect to it
{.ConnectionString = "Server=.\SQLEXPRESS;Database=Test;User=sa;Pwd=test;"}
Now i want to deploy that application so my friend can test it. I have no idea how to make it possible or is it possible at all ( is the database on my localhost ) ?
I would really could use some help because first time working with it.

You can create local mdf database file in your project and slightly change your connection string to attach it to sqlexpress instance.
"Data Source=.\SQLEXPRESS;
AttachDbFilename=test.mdf;
Integrated Security=True;
User Instance=True";
It worth to mension that your friend has to have sql server express installed.

I think the best way is to make a backup of your DB as follows.BACKUP DATABASE [Accounting] TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\Test.bak' WITH NOFORMAT, INIT, NAME = N'Accounting-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
then they can restore it as follows on there mssqlserver:
RESTORE DATABASE [DBRooiabooking] FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\Test.bak' WITH FILE = 1, NOUNLOAD, STATS = 5
and they can use it .
with the same connectionstring .
Best Regards

Related

How do I call a remote T-SQL procedure to restore a remote .bak database file to a remote SQL Server instance?

I have backed up an SQL Server database to a file called HACK_BACK.bak. I have copied that .bak file to a remote server that hosts another SQL Server instance.
That remote server has a procedure called RestoreDatabase which has code to restore the .bak file to that remote SQL Server instance.
On my local SQL Server database, I have a linked server that connects to that server where I call that RestoreDatabase procedure.
When I call that remote procedure using the linked server, I get this error:
Cannot open backup device 'G:\DROPZONE\HACK_MACK.bak'. Operating system error 2(The system cannot find the file specified.).
This remote procedure is being called from my local SQL Server, but the context of execution appears to be local which is why I get the error. I want the procedure to use the remote server's G: drive and to restore that .bak file to that remote SQL Server instance.
How do I do that?
Hmm, if you call the remote proc like this on your local, it should work
--linked server = REMOTE
EXEC REMOTE.DB.RestoreDatabase 'G:\fileToRestore.bak'
That should run it on the REMOTE SQL instance with local G:, no?
I'm not sure what exact sequence you're running now
Another option is maybe use PowerShell (outside of SQL) to connect to REMOTE SQL instance to initiate the procedure to restore. Heck, look into dbatools.io even

A basic SQL Server Backup strategy / tool

I have a SQL Server 2014 running on Windows Server 2012 R2. I want to back it up daily and store backups on some remote cloud storage for reliability. Basically, that is all of my requirements.
Is there a tool that can help with this? The easier and plainer the better.
I don't see any app providing native support for cloud backups.But you can use SQLServer 2014 to backup to cloud using SQLServer Agent
Below are steps
1.create credential
CREATE CREDENTIAL MyCredentialName
WITH IDENTITY = 'MyStorageAccountName',
SECRET = 'MyAccessKey';
2.Backup
BACKUP DATABASE MyNewDB TO
URL = N'http://myserver.blob.core.windows.net/scarybu/MyNewDB.bak'
WITH CREDENTIAL = N'MyCredentialName',
NAME = N'MyNewDB-Full Database Backup', STATS = 10;
You could also experiment by adding compression ,checksum to above syntax by looking at all options..You can see below link for more experiments and results done by Jovan Popovic :Native database backup in Azure SQL Managed Instance..You can ignore copy_only syntax in the link examples,since it is only for managed instances

SQL Server database stuck in restoring state after BACKUP LOG WITH NORECOVERY

Used SQL Server Management Studio to restore a database but "Take tail-log backup with NORECOVERY" was checked and user didn't have permission to RESTORE database.
So T-SQL commands executed in this order (generated in SQL Server Management Studio):
BACKUP LOG [database]
TO DISK = N'...DatabaseBackup_2016-08-28_14-07-05.bak'
WITH NOFORMAT, NOINIT,
NAME = N'...DatabaseBackup_2016-08-28_14-07-05', NOSKIP, NOREWIND,
NOUNLOAD, NORECOVERY, STATS = 5
Executed OK
RESTORE DATABASE [database]
FROM DISK = N'....database.bak'
WITH FILE = 1.....
Failed (User doesn't have right for RESTORE)
RESTORE DATABASE <database> WITH RECOVERY
doesn't work because of permission
So the question is how to release database from restoring state and how did the server allow me to set database into restoring state without permission?
Permissions for BACKUP and RESTORE operations are different.
https://msdn.microsoft.com/en-us/library/ms186858.aspx
https://msdn.microsoft.com/en-us/library/ms186865.aspx
, so the user may have permissions to backup the log and put it into restoring mode, but may not have permissions to restore the database.
Modify the user permissions, it should work.

SQL Server: Database stuck in “Restoring” state with PHP

I tried to backup my database following the instruction from SQL Server: Database stuck in "Restoring" state. but i have my database stuck in "Restoring" state. php code below:
$database = "container";
$uid = "sa";
$pwd = "12345" ;
try {
$conn = new PDO( "sqlsrv:Server=localhost\SQLEXPRESS;Database=$database",
$uid,
$pwd
//,array(PDO::ATTR_PERSISTENT => true)
);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); }
catch( PDOException $e ) {
die( "Error connecting to SQL Server" ); }
echo "Connected to SQL Server\n";
$backfile = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\sql server bk' ;
echo "Connected to SQL Server\n";
$backfile = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\sql server bk' ;
$query = "RESTORE DATABASE child_database FROM DISK = '$backfile' WITH REPLACE, RECOVERY ";
$conn->exec($query);
After running this code I got my child_database stuck in restoring state.however I copy the sql command
RESTORE DATABASE child_database FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\sql server bk' WITH REPLACE, RECOVERY
and run in microsoft sql server management tool it works just fine.
I try to run add php code
$conn->exec("RESTORE DATABASE child_database WITH RECOVERY");
I got an exception.
please help.
It seems have problem with PDO driver, this problem may be in the ODBC/SNAC layer on which the driver is built. But this database restoring works well with other drivers.
I tried with sqlsrv and mssql, they worked well.
For more detail, see Restoring a SQL Server Database from PHP

Maintenance Plan Fails But Query Runs

I have an SQL Server 2005 Enterprise Edition whose Maintenance plan fails constantly with the error:
backup MYSERVER (MYSERVER)
Backup Database on MYSERVER
Databases that have a compatibility level of 70 (SQL Server version 7.0) will be skipped.
Databases: All databases
Type: Differential
Append existing
Task start: 2011-10-18T00:10:09.
Task end: 2011-10-18T00:10:09.
Failed:(-1073548784) Executing the query "BACKUP DATABASE [model] TO DISK = N'\\myNetworkDrive\\opovo\\BackupSQL\\MYSERVER\\model\\model_backup_201110180010.bkp' WITH DIFFERENTIAL , RETAINDAYS = 13, NOFORMAT, NOINIT, NAME = N'model_backup_20111018001008', SKIP, REWIND, NOUNLOAD, STATS = 10
" failed with the following error: "Cannot open backup device 'C:\\Program Files\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\Backup\\Arca\\opovo\\BackupSQL\\MYSERVER\\model\\model_backup_201110180010.bkp'. Operating system error 3(The system cannot find the path specified.).
BACKUP DATABASE is terminating abnormally.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
But the query:
BACKUP DATABASE [model] TO DISK = N'\\myNetworkDrive\\opovo\\BackupSQL\\MYSERVER\\model\\model_backup_201110180010.bkp' WITH DIFFERENTIAL , RETAINDAYS = 13, NOFORMAT, NOINIT, NAME = N'model_backup_20111018001008', SKIP, REWIND, NOUNLOAD, STATS = 10
runs normally and gives me the expected results.
Is this a bug?
What am I missing here?
What is the elegant way to backup to a network location?
You need to check the account that SQL Server Agent service runs as. If the account doesn't have permissions on that network share, then it won't be able to see that path. Executing that query outside of a SQL Server Agent job (indirectly through a maintenance plan) doesn't use the security context of the SQL Server Agent service.
Make the SQL Server Agent service run as a domain account with access to that network share.

Resources