How do I release sql express database?
来源:互联网 发布:电视机品牌 知乎 编辑:程序博客网 时间:2024/06/09 22:47
Questions
I have a simple app thatuses an SQL Express 2005 database. When the user closes the app, I wantto give the option to back up the database by making a copy in anotherdirectory. However, when I try to do it, I get "The process cannotaccess the file '.../Pricing.MDF' because it is being used by anotherprocess." I closed the connection, disposed the connection, set it tonothing, and GC.Collect(), but it makes no difference. My connectionstring is "DataSource=./SQLEXPRESS2005;AttachDbFilename=|DataDirectory|/Pricing.mdf;IntegratedSecurity=True; User Instance=True" and I just keep using the sameconnection throughout. I didn't see where I could detach the databaseto counter the attach in the connection string.
1 - How do I RELEASE the thing? 2 - Is there a better way than justcopying the database? The app is for my husband only, so I will be ableto 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 ofthe changes in the transaction log, take a look at the modified timeafter running some queries, it doesn't write directly to the file. Inoticed 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 callingthe T-SQL which you can completely automate as far as source db anddestination folder:
SQL 2005 had introduced another T-SQL syntax to do this, for the lifeof me I can't find it. But there are ways to do it through M$$SQLwithout having the full blown database server.
- How do I release sql express database?
- How Do I Enable Remote Access To MySQL Database Server?
- How do I?
- OpenXML: How do I?
- How should I Install SQL Server 2008 Express Edition
- How do I upload or download XML to/from a database
- 如何改变Visual Assist数据库文件路径(How do I change where VA stores its database?)
- How do I love thee
- How do I love thee
- How do I control appearance?
- How do I Install VE?
- How do I use IStream?
- How do I configure SMPP?
- How do I love thee
- How do you build a database?
- How do you build a database?
- How do i prevent end users from connecting to the database other than my application?", version 8.1.5
- How do you build a database? (self.Database)
- 粗粒度看世界续--关于地震
- java 读取一个excel
- Windows无法连接到选定网络,网络可能不在区域中。请刷新可用网络的列表,重新尝试(转)
- 进程|线程
- DataSnap 2009 系列
- How do I release sql express database?
- 黑谍旺旺群发V3.11绿色注册版
- debian学习第一天
- 水晶报表11.5专业版(正式版) 序列号 cdkey 密钥
- 条款20:宁以pass-by-reference-to-const替换pass-by-value
- 起步停车口诀
- 从电影到multi-touch再到几句闲话
- MATLAB中均值、方差、均方差的计算方法
- 手机使用小秘诀,让你的手机永远有电!(转载)