易截截图软件、单文件、免安装、纯绿色、仅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索引管理之六大铁律


原文转自:http://tech.it168.com/a2009/0218/265/000000265868.shtml
索引是以表列为基础的数据库对象。索引中保存着表中排序的索引列,并且纪录了索引列在数据库表中的物理存储位置,实现了表中数据的逻辑排序。通过索引,可以加快数据的查询速度和减少系统的响应时间;可以使表和表之间的连接速度加快。
  但是, ......

sql server和oracle的区别

1.Oracle为客户端开启会话有两种方式:共享服务和专用服务。在专用服务情况下,监听器为连接请求创建新进程(Unix环境下是Process,Windows下我想应该是Thread吧);共享服务情况下,监听器将客户请求交给Dispatcher,由Dispatcher安排多客户的作业。SQL Server在默认情况下自动为客户端连接创建线程,当有非常多的客 ......

维护Oracle常用SQL语句

       如何远程判断Oracle数据库的安装平台
  select * from v$version;
  查看表空间的使用情况
  select sum(bytes)/(1024*1024) as free_space,tablespace_name
  from dba_free_space
  group by tablespace_name;
  SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES ......

SQL Server 2005 镜像构建手册

一、 镜像简介
1、 简介
数据库镜像是将数据库事务处理从一个SQL Server数据库移动到不同SQL Server环境中的另一个SQL Server数据库中。镜像不能直接访问;它只用在错误恢复的情况下才可以被访问。
要进行数据库镜像所需的最小需求包括了两个不同的SQL Server运行环境。主服务器被称为“主机”,第二个服务器被 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号