Re: SQL Express backup

Tech-Archive recommends: Speed Up your PC by fixing your registry



"Scott" <Scott@xxxxxxxxxxxxxx> wrote in message news:yPBim.176358$ZN.173615@xxxxxxxxxxxxxxx
Hello,
I have an interesting situation with my website and I'm not sure if it would be better to ask here or a SQL forum. So I'll start here and see what you all say.
In my asp.NET website I have two SQL express databases. One for logon credentials and another for page content. I cannot backup the MDF files because they are constantly in use. A while back I came accross the following comand line that would do the backup:
-------------Command Line--------------------
c:\sqlcmd -S .\SQLExpress -i E:\ClientAccess\VP_v2.0\SQLBackup\Backup.sql -o c:\sqlcmd -S .\SQLExpress -i E:\ClientAccess\VP_v2.0\SQLBackup\Backup_Log.txt
------------------------------------------------
------------------Bckup.sql --------------------
USE [master]
GO
sp_attach_db "Database", "E:\ClientAccess\VP_v2.0\App_Data\Database.mdf"
GO
BACKUP DATABASE [Database] TO DISK='E:\ClientAccess\VP_v2.0\SQLBackup\Database.bak' WITH FORMAT
GO
sp_detach_db [Database]
GO
sp_attach_db "ASPNETDB", "E:\ClientAccess\VP_v2.0\App_Data\ASPNETDB.MDF"
GO
BACKUP DATABASE [ASPNETDB] TO DISK='E:\ClientAccess\VP_v2.0\SQLBackup\ASPNETDB.bak' WITH FORMAT
GO
sp_detach_db [ASPNETDB]
GO
--------------------------------------------------

This all works well and good but every so often the site stops working because the file permissions on Database.mdf and ASPNETDB.MDF get changed to something that doesn't allow the site to use the DB files and causes a "Cannot open user default database. Login failed. Login failed for user 'NT AUTHORITY\NETWORK SERVICE'." error when someone tries to log in. I have enabled autiting on the directory these files are in and I think I've traced it back to my backup script. Can anyone tell me if I'm doing something wrong or perhaps offer a different solution? Maybe someone has seenthis before and has fixed it.

Probably not the "best" group, but I know of few devs who know nothing about SQL Server, and there are plenty of us who could probably serve as DBAs for many companies. If you want a more thorough explanation of the "whys" and "wherefores", I would still ask in the SQL programming group.

I am not understanding the attach of the database. Are you running the mdf file from inside the web site (the auto attach to SQL Express option)? If so, why does it have to be this way? Note I am not saying that it does not, but you can have a database permanently attached to SQL Express and then you can use backup without the attach necessary, which will not interfere with the website.

What you are doing is attaching, which temporarily detaches from the automagic attach in the web site. The backup is then complete and detatched and everything is back to normal. During the time you attach, however, you are creating a problem for the website.

My suggestion would be to permanently attach and then alter your connection string to the Express instance. You can then run a backup script, sans attach, and not interfere with your web clients.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

********************************************************
| Think outside the box! |
********************************************************

.



Relevant Pages

  • Re: SQL Express backup
    ... I will post this in the SQl group and see what they say too. ... I cannot backup the MDF files ... BACKUP DATABASE TO ... I am not understanding the attach of the database. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: SQL Express backup
    ... AUTHORITY\NETWORK SERVICE account? ... In my asp.NET website I have two SQL express databases. ... I cannot backup the MDF files ... BACKUP DATABASE TO ...
    (microsoft.public.sqlserver.programming)
  • SQL Express backup
    ... would be better to ask here or a SQL forum. ... In my asp.NET website I have two SQL express databases. ... I cannot backup the MDF files ... BACKUP DATABASE TO ...
    (microsoft.public.dotnet.framework.aspnet)
  • SQL Express backup
    ... In my asp.NET website I have two SQL express databases. ... I cannot backup the MDF files ... BACKUP DATABASE TO ... "Cannot open user default database. ...
    (microsoft.public.sqlserver.programming)
  • Re: Attach Database
    ... will allow you to attach such an MDF file without problems? ... SQL Server MVP ... In both cases, the database can ... >>> restoring a database from a backup. ...
    (microsoft.public.sqlserver.server)