易截截图软件、单文件、免安装、纯绿色、仅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注入式攻击


SQL注入式攻击是利用是指利用设计上的漏洞,在目标服务器上运行Sql命令以及进行其他方式的攻击动态生成Sql命令时没有对用户输入的数据进行
验证是Sql注入攻击得逞的主要原因。
比如:
如果你的查询语句是select * from admin where
username="&user&" and password="&pwd&"&quo ......

SQL Server Out Put Excel File

SQL Server Out Put Excel File
在 SQL Server中, 导出EXCEL 文件, 用到 bcp.exe
 
 bcp  导出的本质是纯文本文档,
若数据含有中文,请导出到中文版EXCEL,或TXT文档等, 否则乱码....
用TXT 打开英文版EXCEL,也可以,
 
导出 数据到C:\authors.xls, 若文件存在则重写文件, 不存在则创建文件
  ......

[摘抄/记录]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 ......

PL/SQL游标变量的调用与作为输出参数的应用

      今天有个学生问我调用包里面具有游标类型的输出参数,可是在用PL/SQL程序调用的时候居然报出参数个数或类型错误的异常信息,于是自己也试了一下,果然是出错了。然后就自己琢磨了一下、查查资料和问问同事,原来问题是很简单的,先看一下程序的结构代码:
CREATE OR REPLACE PACKAGE Pkg_S ......

SQL Server 2005 镜像功能实现

SQL Server 2005 镜像功能实现
1. 主机、镜像分别MASTER KEY。
主机执行: 
USE master;  
  
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'password';  
  
CREATE CERTIFICATE HOST_A_cert WITH  ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号