473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Problem with "locked" SQL Server Express database files - Please help!

Hi all,

I have a major problem with my ASP.NET website and it's SQL Server
2005 Express database, and I'm wondering if anyone could help me out
with it.

This site is on a webhost (WebHost4Life) and was running fine and
dandy, until I decided I needed to add some additional stored
procedures to the database.

I made these changes locally, and uploaded the changed files, which
included the .MDF file for the database, overwriting the files that
were on my host. I did not upload the .LDF file (and WebHost4Life say
not to, since you can get errors like "database already exists for
this user), and now my website is broken.

I'm getting an error that my primary database file does not match my
log file. I have attempted to delete both the .MDF and .LDF files,
hoping to reload, but they're locked, and cannot be deleted or
renamed.

I believe the "lock" on these files is due them being currently
"attached" to the SQLServer Express instance running on my webhost.
I'm led to believe this, since I've tried all kinds of things to get
this to work, including uploading a "copy" of the .MDF file with a
different filename, and attempting to attach a different file (in the
AttachDBFilename section of the connection string) but with the same
"name" attribute. This gave me a different error saying that it could
not attach this new database since one with the same name was already
attached.

My connection string within my web.config file is shown below:
<add name="MyDB" connectionString="data source=.\SQLEXPRESS;Integrated
Security=True;AttachDBFilename=|DataDirectory|MyDB .mdf;User
Instance=True;Initial Catalog=MyDB"
providerName="System.Data.SqlClient" />

As can be seen by my connection string, I'm using "User Instance=True"
which I thought would create a separate user instance of
SQLServer2005Express, but that this instance exists only for the
lifetime of my .NET web application. Thus, I thought that shutting
down my .NET application, using the "app_offline.htm" trick, that this
would kill my .NET app. instance, which in turn would kill the
SQLServer user instance, thus unlocking my .MDF and .LDF files.
However, this appears not to be the case, as the files (even after
leaving things alone for a few hours, in case of some kind of caching
etc.) are still locked, and cannot be deleted.

Does anyone know of a way for me to unlock these files? I'm thinking
I may have to "detach" the old database somehow, but I can't connect
to it in the first place through my web application, and
unfortunately, since this site is on a remote webhost, I don't have
full access to IIS or the SQLServer service/instances.

Any and all help on this matter is greatly appreciated.

Thanks in advance.
Glen.

Feb 4 '07 #1
5 14404
Glen Buell wrote:
Does anyone know of a way for me to unlock these files? I'm thinking
I may have to "detach" the old database somehow, but I can't connect
to it in the first place through my web application, and
unfortunately, since this site is on a remote webhost, I don't have
full access to IIS or the SQLServer service/instances.

Any and all help on this matter is greatly appreciated.

Thanks in advance.
Glen.
Glen,

I think someone who can admin their SQL Server will have to detach the
database for you.

Jonathan
Feb 4 '07 #2
You can close the connection held by Visual Web Developer by right-clicking the
database in Solution Explorer and selecting the Detach option, or by right-clicking
the database in Server Explorer and selecting Close Connection.

Visual Web Developer will automatically close any open
database connections when you run or debug your Web application.

Additionally, if you need to release any open connections to a SQL Server Express Edition
database, you can unload your Web application by using Internet Information Services Manager
(IIS Manager).

You can also unload a Web application by adding an HTML file named App_offline.htm to the
root directory of your Web application. To allow your Web application to start responding to
Web requests again, simply remove the App_offline.htm file.

You will need to release open connections to a SQL Server Express Edition
database when you want to copy or move the database to a new location.

Also, you might want to consider using the SQL Server Express Utility:

http://www.microsoft.com/downloads/d...DisplayLang=en

SQL Server 2005 Management Studio Express also allows you to detach databases :
http://download.microsoft.com/downlo...LExpwSSMSE.doc


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================

"Glen Buell" <gl*******@mailinator.comwrote in message
news:i9********************************@4ax.com...
Hi all,

I have a major problem with my ASP.NET website and it's SQL Server
2005 Express database, and I'm wondering if anyone could help me out
with it.

This site is on a webhost (WebHost4Life) and was running fine and
dandy, until I decided I needed to add some additional stored
procedures to the database.

I made these changes locally, and uploaded the changed files, which
included the .MDF file for the database, overwriting the files that
were on my host. I did not upload the .LDF file (and WebHost4Life say
not to, since you can get errors like "database already exists for
this user), and now my website is broken.

I'm getting an error that my primary database file does not match my
log file. I have attempted to delete both the .MDF and .LDF files,
hoping to reload, but they're locked, and cannot be deleted or
renamed.

I believe the "lock" on these files is due them being currently
"attached" to the SQLServer Express instance running on my webhost.
I'm led to believe this, since I've tried all kinds of things to get
this to work, including uploading a "copy" of the .MDF file with a
different filename, and attempting to attach a different file (in the
AttachDBFilename section of the connection string) but with the same
"name" attribute. This gave me a different error saying that it could
not attach this new database since one with the same name was already
attached.

My connection string within my web.config file is shown below:
<add name="MyDB" connectionString="data source=.\SQLEXPRESS;Integrated
Security=True;AttachDBFilename=|DataDirectory|MyDB .mdf;User
Instance=True;Initial Catalog=MyDB"
providerName="System.Data.SqlClient" />

As can be seen by my connection string, I'm using "User Instance=True"
which I thought would create a separate user instance of
SQLServer2005Express, but that this instance exists only for the
lifetime of my .NET web application. Thus, I thought that shutting
down my .NET application, using the "app_offline.htm" trick, that this
would kill my .NET app. instance, which in turn would kill the
SQLServer user instance, thus unlocking my .MDF and .LDF files.
However, this appears not to be the case, as the files (even after
leaving things alone for a few hours, in case of some kind of caching
etc.) are still locked, and cannot be deleted.

Does anyone know of a way for me to unlock these files? I'm thinking
I may have to "detach" the old database somehow, but I can't connect
to it in the first place through my web application, and
unfortunately, since this site is on a remote webhost, I don't have
full access to IIS or the SQLServer service/instances.

Any and all help on this matter is greatly appreciated.

Thanks in advance.
Glen.

Feb 4 '07 #3
Firstly, thank you Jonathan and Juan for replying to my post, and for
the advice you have provided.

Next, I'd like to say that this issue is now resolved, thanks to my
webhost being very gracious and "unlocking" the files for me. I also
realise that this is really entirely my own fault for stupidly
uploading a new .MDF file (overwriting the old one) whilst leaving the
old .LDF file in place.

My question now is one of best-practise with regard to replacing a
remote SQLServer 2005 Express database on a remote web host. I am not
concerned with the data inside the database, since I use the database
purely for statistic logging, and it's not the end of the world if a
few records don't get written whilst I'm in the process of "upgrading"
it.

Am I right in thinking that if I use the "app_offline.htm" trick
(which should shut-down any and all instances of my .NET web app and
prevent new instances from being instantiated), then my existing .MDF
AND .LDF files should (eventually) become unlocked, thereby allowing
me to delete the existing files (both the MDF and LDF) and re-upload
(via FTP) the new MDF file, before removing the "app_offline.htm"
file, allowing my application to restart ?

Basically, I'm looking for a way to "shut-down" my application
temporarily, ensure that the database files are entirely unused by any
process on the host machine (ie. IIS, SQLEXPRESS etc.) therefore
alowing me to delete/rename/overwrite these database files with
impunity before "upgrading" my dtabase and bringing my application
back "online".

I have a feeling that the "app_offline.htm" method is the way to
achieve this (since that's kinda what it's there for), but I'd just
like confirmation from anywone that may have used this methodology for
the same sort of reasons as myself.
Thanks again in advance.
Regards,
Glen.
On Sun, 4 Feb 2007 17:19:46 -0400, "Jonathan" wrote:
>
Glen,

I think someone who can admin their SQL Server will have to detach the
database for you.

Jonathan
On Sun, 4 Feb 2007 17:19:46 -0400, "Juan T. Llibre"
<no***********@nowhere.comwrote:
>You can close the connection held by Visual Web Developer by right-clicking the
database in Solution Explorer and selecting the Detach option, or by right-clicking
the database in Server Explorer and selecting Close Connection.

Visual Web Developer will automatically close any open
database connections when you run or debug your Web application.

Additionally, if you need to release any open connections to a SQL Server Express Edition
database, you can unload your Web application by using Internet Information Services Manager
(IIS Manager).

You can also unload a Web application by adding an HTML file named App_offline.htm to the
root directory of your Web application. To allow your Web application to start responding to
Web requests again, simply remove the App_offline.htm file.

You will need to release open connections to a SQL Server Express Edition
database when you want to copy or move the database to a new location.

Also, you might want to consider using the SQL Server Express Utility:

http://www.microsoft.com/downloads/d...DisplayLang=en

SQL Server 2005 Management Studio Express also allows you to detach databases :
http://download.microsoft.com/downlo...LExpwSSMSE.doc


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================

"Glen Buell" <gl*******@mailinator.comwrote in message
news:i9********************************@4ax.com.. .
>Hi all,

I have a major problem with my ASP.NET website and it's SQL Server
2005 Express database, and I'm wondering if anyone could help me out
with it.
[SNIP!]
Feb 5 '07 #4
Glen Buell wrote:
Basically, I'm looking for a way to "shut-down" my application
temporarily, ensure that the database files are entirely unused by any
process on the host machine (ie. IIS, SQLEXPRESS etc.) therefore
alowing me to delete/rename/overwrite these database files with
impunity before "upgrading" my dtabase and bringing my application
back "online".

I have a feeling that the "app_offline.htm" method is the way to
achieve this (since that's kinda what it's there for), but I'd just
like confirmation from anywone that may have used this methodology for
the same sort of reasons as myself.
Glen,

First, I should say that I am not a developer, but a DBA. I could be
wrong but I would be very surprised if this will detach the database for
you. You normally do this through an admin GUI of some sort. SQL 2005
uses SSMS; 2000 used Enterprise Manager. ** Many web hosts provide
neither but provide their own web-based control panel application. I
would start with your ISP. If they offer SQL, they should know the
answer - should be a common question.

Sorry, I could not advise more definitively.

Jonathan
Feb 6 '07 #5
On Mon, 05 Feb 2007 19:53:47 -0600, Jonathan Roberts
<gr*******@diynics.comwrote:
>Glen Buell wrote:
>Basically, I'm looking for a way to "shut-down" my application
temporarily, ensure that the database files are entirely unused by any
process on the host machine (ie. IIS, SQLEXPRESS etc.) therefore
alowing me to delete/rename/overwrite these database files with
impunity before "upgrading" my dtabase and bringing my application
back "online".

I have a feeling that the "app_offline.htm" method is the way to
achieve this (since that's kinda what it's there for), but I'd just
like confirmation from anywone that may have used this methodology for
the same sort of reasons as myself.

Glen,

First, I should say that I am not a developer, but a DBA. I could be
wrong but I would be very surprised if this will detach the database for
you. You normally do this through an admin GUI of some sort. SQL 2005
uses SSMS; 2000 used Enterprise Manager. ** Many web hosts provide
neither but provide their own web-based control panel application. I
would start with your ISP. If they offer SQL, they should know the
answer - should be a common question.

Sorry, I could not advise more definitively.

Jonathan
Hi Jonathan,

Thanks again for replying to my post.

I think you're exactly right about having to "manually" attach/detach
database files, but I think this only applies to the various
"full-blown" editions of SQL Server 2005 (ie. Standard, Enterprise
etc.).

I'm under the impression that SQL Server 2005 EXPRESS operates
slightly differently. Certainly, the ATTACHING of a database file is
done dynamically when using ASP.NET, as the connectionstring that is
used to connect to a SQL2005Express database contains a section like
this:
AttachDBFilename=database.mdf

This instructs the SQL Express instance to dynamically attach the file
specified at run-time, without any intervention from a DBA/Admin at
all.

Another section of the connection string has syntax like this:
User Instance = True

This instructs SQL2005Express to create a new "instance" of the
SQLExpress service, running under the user account from which it is
created.

The following MSDN link is quite helpful:
http://msdn2.microsoft.com/en-us/library/bb264564.aspx

In fact, I think I may have answered my own question here, since that
link does say that "user instances" of SQLServer2005Express are
automatically "shut-down" after the last connection using them is
closed. I think it says that the default time for this is 60 minutes,
but that it is configurable. I'm assuming that when the "user
instance" is shut-down, the database that was previously attached to
that instance will be automatically detached, thus removing any
OS-level file locks.

Thanks again for your help. Seems that between us all, we've stumbled
on the answer.

Regards,
Glen.

Feb 6 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jack | last post by:
I have a form that has few text boxes to input. However, after saving, if the user comes back to the same form, then the input boxes should be locked. I would like to know whether this can be...
10
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in...
4
by: Giggle Girl | last post by:
I have inherited a stylesheet at work, with the designer no longer working here. In an external stylesheet it says: thead th, thead th.locked { position:relative; }
1
by: amindi | last post by:
Hi, I wrote a VB6 program to read some data records from a Ms Access database and to write them into a SQL server database.(I use Ms Access 2000 and SQL server 2000).After reading each record in...
2
by: CWogksch | last post by:
Hello, Everyone... My name is Chris Wogksch. I have a point of sale application developed in VB6 using MS Access 2003 as the database. I've been running versions of this app for over eight...
0
by: CWogksch | last post by:
Hello, Everyone... My name is Chris Wogksch. I have a point of sale application developed in VB6 using MS Access 2003 as the database. I've been running versions of this app for over eight...
2
by: boliches | last post by:
I have a form within my database which On Open (event procedure) will make many calculations and enter the results in text boxes on the page of the form (I have 2 tabs on this particular form). My...
3
by: rubbishemail | last post by:
Hello, do you know of any way to copy locked / opened files under win xp? I know there is something like "Volume Shadow Copy" but I don't know how to use it. Maybe someone already has a python...
1
by: =?Utf-8?B?R29yZG9uUw==?= | last post by:
Hello, I am unsure which group this should go under so have placed it on the general, if anybody can suggest a more appropriate group that would be great. I have a problem whereby if I update...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.