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.
Ïà¹ØÎĵµ£º
1£®OracleΪ¿Í»§¶Ë¿ªÆô»á»°ÓÐÁ½ÖÖ·½Ê½£º¹²Ïí·þÎñºÍרÓ÷þÎñ¡£ÔÚרÓ÷þÎñÇé¿öÏ£¬¼àÌýÆ÷ΪÁ¬½ÓÇëÇó´´½¨Ð½ø³Ì£¨Unix»·¾³ÏÂÊÇProcess£¬WindowsÏÂÎÒÏëÓ¦¸ÃÊÇThread°É£©£»¹²Ïí·þÎñÇé¿öÏ£¬¼àÌýÆ÷½«¿Í»§ÇëÇ󽻸øDispatcher£¬ÓÉDispatcher°²ÅŶà¿Í»§µÄ×÷Òµ¡£SQL ServerÔÚĬÈÏÇé¿öÏÂ×Ô¶¯Îª¿Í»§¶ËÁ¬½Ó´´½¨Ị̈߳¬µ±Óзdz£¶àµÄ¿Í ......
SQL Server Out Put Excel File
ÔÚ SQL ServerÖÐ, µ¼³öEXCEL Îļþ, Óõ½ bcp.exe
bcp µ¼³öµÄ±¾ÖÊÊÇ´¿Îı¾Îĵµ,
ÈôÊý¾Ýº¬ÓÐÖÐÎÄ,Çëµ¼³öµ½ÖÐÎİæEXCEL,»òTXTÎĵµµÈ, ·ñÔòÂÒÂë....
ÓÃTXT ´ò¿ªÓ¢ÎİæEXCEL,Ò²¿ÉÒÔ,
µ¼³ö Êý¾Ýµ½C:\authors.xls, ÈôÎļþ´æÔÚÔòÖØÐ´Îļþ, ²»´æÔÚÔò´´½¨Îļþ
  ......
×ªÔØÒ»¸öBDBµÄÏà¹Ø½éÉÜ£¬»ù±¾¿ÉÒÔµ±ËÙ³ÉÊÖ²áÓ㬸ü¶àµÄÎĵµ¿ÉÒÔÈ¥Oracle¹Ù·½ÍøÕ¾ÏÂÔØ¡£
SQL ¿ª·¢ÈËÔ± Oracle Berkeley DB Ö¸ÄÏ
×÷ÕߣºMargo Seltzer
Oracle Berkeley DB Öг£Óà SQL º¯ÊýʹÓÃÖ¸ÄÏ¡£
2007 Äê 9 Ô·¢±í
³£³£ÓÐÈËÎÊ Oracle Berkeley DB “ÎÒÈçºÎÔÚ Berkeley DB ÖнøÐÐ <SQL ²éѯ>£¿"Òò´Ë£¬ÎÒÃÇ ......
db2 µ÷ÓÃsql½Å±¾³£ÓÃÃüÁdb2 -tf d:\creat_table.sql Óë db2 -td$ -f d:\creat_table.sql
db2 -tf d:\creat_table.sql µ÷Óýű¾ÃüÁîÊÇddl²Ù×÷
µ±Óöµ½sqlÓï¾ä¹ý³¤£¬»òÌáʾ DB21007E ¶ÁÈ¡¸ÃÃüÁîʱÒѵ½´ïÎļþĩβ¡£¾ÍʹÓà db2 -td$ -f d:\creat_table.sql ÃüÁî
ʹÓøÄÃüÁîÐèÒªÔÚsql½Å±¾ÖÐÒÔ$½áÊ ......
SQL Server 2005 ¾µÏñ¹¦ÄÜʵÏÖ
1. Ö÷»ú¡¢¾µÏñ·Ö±ðMASTER KEY¡£
Ö÷»úÖ´ÐУº
USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'password';
CREATE CERTIFICATE HOST_A_cert WITH ......