detach aspnetdb database database

Last post 05-12-2008 10:10 AM by TheEagle. 12 replies.

Sort Posts:

  • detach aspnetdb database database

    05-06-2008, 1:26 AM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    Hi,

    Iam facing problems to connect to the new database after detach the aspnetdb.Simply the new database disappear (In SQL 2005 Management studio express the database contents disappear ! and I get an error when try to open it).If I try to connectto aspnetdb again I get an error telling me it is used by another process.I don't understand what is going on could any one explain to me?  

  • Re: detach aspnetdb database database

    05-06-2008, 2:33 AM
    • Loading...
    • rbansal44
    • Joined on 12-11-2007, 10:09 AM
    • Posts 89

    hi,

    use this command in the sql query.... 

    sp_detatch_db 'Database name'

     

    thanks,

    rajiv

    Remember To mark as answer if it answered your question.

  • Re: detach aspnetdb database database

    05-08-2008, 6:41 AM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    I have detach the aspnetdb file already and attach a batabase successfuly but the problem when I run the application I get the error:

    The process cannot access the file '....\aspnetdb.mdf' because it is being used by another process.I set the connection string to my new database so what cause this error and how to fix it? 

  • Re: detach aspnetdb database database

    05-08-2008, 6:52 AM
    • Loading...
    • ShivaKarthik
    • Joined on 04-15-2008, 1:11 PM
    • Hyderabad
    • Posts 161

    Hi Buddy,

    I think although you detached the database from your pc actually its not detached in the server.

    So you have to come across some stored procedures

    Please refer the following one www.msdn.com

    Mark As Answer If this helps you

    Further Queries Recommended

    Happy CodingWink

    Regards,
    B.ShivaKarthik
    Software Engineer
    Hyderabad,India
  • Re: detach aspnetdb database database

    05-08-2008, 10:20 AM
    • Loading...
    • XPSCodes
    • Joined on 03-12-2008, 3:17 AM
    • New Jersey
    • Posts 444

     If you have aspnetdb attached in Management studio and if the webconfig is using attachdbfilename, its not going to work.

    To get this to work, 

    Either detach the aspnetdb from management studio before you run the application

    or

    Change the connection string to use database=aspnetdb

    Save our world, its all we have! A must watch video Pale Blue Dot

    Please use the search feature of the forum before asking a question.
  • Re: detach aspnetdb database database

    05-10-2008, 2:23 AM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    Thank you for your respond.The aspnetdb file doesn't appear in the management studio.How could I run the stored procedure you mentioned on the aspnetdb database file.The database is attached successfully to my new sql express server database with a new name.I can see it in visualstudio.but still when I try to run the application I get the error :

    The process cannot access the file '...\ASPNETDB.MDF' because it is being used by another process.The connectionString seems to me set correctly.

    When I try to exclude the aspnetdb file I get a similar error message to the one above.  

  • Re: detach aspnetdb database database

    05-11-2008, 4:41 AM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    XPSCodes:

     If you have aspnetdb attached in Management studio and if the webconfig is using attachdbfilename, its not going to work.

    To get this to work, 

    Either detach the aspnetdb from management studio before you run the application

    or

    Change the connection string to use database=aspnetdb

    As I read in a book I detached the aspnetdb file in the visualstudio.net solution explorer then in management studio express I attach the file with a new name.Then I modify the connection string to connect to the sqlexpress server database as  the following:

    <remove name="LocalSqlServer"/>
      <add name="LocalSqlServer" connectionString="Data Source=MYCOMPUTER\SQLEXPRESS;Initial Catalog=NewDatabaseName;Integrated Security=True" />
      

    I just observed that my connection string is for sql express instances(.dbo) not for an .mdf file so if I want the database file to still attached to the management studio(the second choice) what the connection string should be?.

  • Re: detach aspnetdb database database

    05-11-2008, 7:42 AM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    Oh noCrying.I have detached the database in management studio and set the connection string to use the aspnetdb.mdf file but the error still exist.

  • Re: detach aspnetdb database database

    05-11-2008, 10:20 PM

    Hi TheEagle ,

    Is your applicatoin(web site) still running? Note that sql express use UserInstance which means when your application is running, the database would be auto-attached to sqlexpress instance and when your application ends up, that database would be auto-detached from sqlexpress. So,even if you have elaborately detached that db from sql express, after you run your application again, and during your application runtime, that db(mdf file) is still attached. Based on my understanding, I think if you try to attach a databse to sqlexrpess which has already been attached, you would get the error message  that you are getting now.

    Hope my suggestion helps

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: detach aspnetdb database database

    05-12-2008, 1:19 AM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    Bo Chen – MSFT:

    Hi TheEagle ,

    Is your applicatoin(web site) still running? Note that sql express use UserInstance which means when your application is running, the database would be auto-attached to sqlexpress instance and when your application ends up, that database would be auto-detached from sqlexpress. So,even if you have elaborately detached that db from sql express, after you run your application again, and during your application runtime, that db(mdf file) is still attached. Based on my understanding, I think if you try to attach a databse to sqlexrpess which has already been attached, you would get the error message  that you are getting now.

    Hope my suggestion helps

    Thank you for responding to me.I have detached that database in the Management studio express.A three options page appeared(keep,drop,..) I leave it as default which was keep then the database disappeared in Management studio express then I set the connection as the following:

    <remove name="LocalSqlServer"/>
        <add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\..\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>

    Then I run the application and the error prevent the application from strating.

    Hope that you can help me as fast as possible.

  • Re: detach aspnetdb database database

    05-12-2008, 2:05 AM

    TheEagle:

    Thank you for responding to me.I have detached that database in the Management studio express.A three options page appeared(keep,drop,..) I leave it as default which was keep then the database disappeared in Management studio express then I set the connection as the following:

    <remove name="LocalSqlServer"/>
        <add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\..\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>

    So you still get that "datbase is used by another process" error. This indicates that aspnetdb.mdf is* still attached to sqlexpress*.  I think you can try to change you connection string to be:

    <remove name="LocalSqlServer"/>
        <add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=&quot;ASP.NET DB&quot   ;Integrated Security=True; providerName="System.Data.SqlClient"/>
    </connectionStrings>

    Hope my suggestion helps

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: detach aspnetdb database database

    05-12-2008, 3:20 AM
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    I remebered that I have another configuration file I created to publish the website so the connectionstring will be replaced.I make it an empty string to be sure it has no effect.I did as you told me and the application start but I get an exception:cannot open database aspnetdb requested by login the login failed.login failed for user MyComputer\ASPNET 

  • Re: detach aspnetdb database database

    05-12-2008, 10:10 AM
    Answer
    • Loading...
    • TheEagle
    • Joined on 04-20-2007, 4:53 AM
    • Posts 128

    After making many things:refresh IIS,detach the Managementstudio database again with the option keep unselected,remove the connection to Managementstudio database in visualstudio.put the default connectionstring,disconnect the aspnetdb database.the application start successfully.But only when I close the database connection otherwise the error appear again.I need always to open the connection to modify the database then close it to pass this error which is not practical.if someone can at least guess what is going on please share us this thread.

Page 1 of 1 (13 items)