易截截图软件、单文件、免安装、纯绿色、仅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 开发人员 Oracle Berkeley DB 指南(zz)

转载一个BDB的相关介绍,基本可以当速成手册用,更多的文档可以去Oracle官方网站下载。
SQL 开发人员 Oracle Berkeley DB 指南
作者:Margo Seltzer
Oracle Berkeley DB 中常用 SQL 函数使用指南。
2007 年 9 月发表
常常有人问 Oracle Berkeley DB “我如何在 Berkeley DB 中进行 <SQL 查询>?"因此,我们 ......

[摘抄/记录]MySQL导入/导出.sql文件

导出.sql文件
 
1.将数据库transfer_server_db导出到transfSRV.sql文件中:
mysqldump -u root -p transfer_server_db > /home/eric/transfSRV.sql
2.将数据库transfer_server_db中的device_info_table导出到table.sql文件中:
mysqldump -u root -p transfer_server_db device_info_table > /home/eric/ta ......

MS SQL Server日期计算

通常,你需要获得当前日期和计算一些其他的日期,例如,你的程序可能需要判断一个月的第一天或者最后一天。你们大部分人大概都知道怎样把日期进行分割(年、月、日等),然后仅仅用分割出来的年、月、日等放在几个函数中计算出自己所需要的日期!在这篇文章里,我将告诉你如何使用DATEADD和 DATEDIFF函数来计算出在你的程序 ......

维护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调整最关注的是什么?

调整的目的就是为了消耗最小的资源来完成功能,通过查看执行计划和各种统计信息来分辨调整后的sql对资源的耗费情况,来找出一个成本最小的sql语句
检查系统的I/O问题
vmstate能检查整个系统的iostat(IO statistics)
查看该SQL的response time(db block gets/consistent gets/physical reads/sorts (disk)) ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号