易截截图软件、单文件、免安装、纯绿色、仅160KB

How do I release sql express database?


Questions
I have a simple app that
uses an SQL Express 2005 database. When the user closes the app, I want
to give the option to back up the database by making a copy in another
directory. However, when I try to do it, I get "The process cannot
access the file '...\Pricing.MDF' because it is being used by another
process." I closed the connection, disposed the connection, set it to
nothing, and GC.Collect(), but it makes no difference. My connection
string is "Data
Source=.\SQLEXPRESS2005;AttachDbFilename=|DataDirectory|\Pricing.mdf;Integrated
Security=True; User Instance=True" and I just keep using the same
connection throughout. I didn't see where I could detach the database
to counter the attach in the connection string.
1 - How do I RELEASE the thing? 2 - Is there a better way than just
copying the database? The app is for my husband only, so I will be able
to handle it if he actually does need to restore from backup.
Thanks!
--------------------------------------------------------------------------------------------------
Answer
You don't want to copy the mdf directly because SQL keeps most of
the changes in the transaction log, take a look at the modified time
after running some queries, it doesn't write directly to the file. I
noticed this while setting up an rsync job.
Having SQL generate the backup is much safer and more desirable,
single-user or multi-user. You can provide a link to a function calling
the T-SQL which you can completely automate as far as source db and
destination folder:
BACKUP DATABASE [mydatabasename]
TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\Scheduled Task Backups\mydatabasename-backup' WITH NOFORMAT, NOINIT, NAME = N'mydatabasename-Full Data
SQL 2005 had introduced another T-SQL syntax to do this, for the life
of me I can't find it. But there are ways to do it through M$$SQL
without having the full blown database server.


相关文档:

SQL Server 2000 各种对象的最大值(数量或大小)

SQL Server 2000 各种对象的最大值(数量或大小)
管理的一个数据库大小将近10G,开始担心数据库会不会过大,查询SQL Server的联机丛书后发现自己的担心真的是多余的。
SQL Server 2000数据库文件大小(数据、日志)最大可以支持 32 TB 的文件
截取SQL Server 2000联机丛书中的最大容量说明方便大家查阅。
SQL Server数据 ......

一些不错的sql语句

1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)
法一:select * into b from a where 1<>1
法二:select top 0 * into b from a
2、说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)
insert into b(a, b, c) select d,e,f from b;
3、说明:跨数据库之间表的拷贝(具体数据使用绝对路 ......

sql备份数据库语句:SQL备份语句

--完整备份
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Full_20070908.bak'
--差异备份
Backup Database NorthwindCS
To disk='G:\Backup\NorthwindCS_Df_20070908.bak'
With Dferential
--日志备份默认截断日志
Backup Log NorthwindCS
To disk='G:\Backup\NorthwindCS_Log_20070908. ......

SQL Server 2005数据库镜像简介

SQL Server 2005数据库镜像简介
自从SQL Server 2000以来,你已经能够通过使用复制来创建一个备用的服务器、传输日志,以及备份和重新存储了——但是现在微软又引入了一个内建的工具,它可以实现自动的错误恢复。数据库镜像是SQL Server 2005的一个新特性,它允许你将一个SQL Server中的数据库内容镜像到另一个S ......

Using Oracle Trace Analyzer (trcanlzr.sql)


Using Oracle Trace Analyzer (trcanlzr.sql)
Dave Moore:  Author of Oracle Utilities
Oracle has provided another utility initially designed for performance tuning Oracle Applications.  Trace Analyzer is provided in the form of a PL/SQL package (TRCA$ ).  The Trace Analyzer utility i ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号