Link to home
Create AccountLog in
Avatar of hconant
hconantFlag for United States of America

asked on

Changing ASP.net website admin tool ASPNETDB default file

I am trying to use a shared server with an ASP.net site and SQL DB's.  The ASP.net WAT (website administration tool=WAT) creates a default db, ASPNETDB.mdf for its security, role, management settings.  This file conflicts with an existing file of same name.  How do you change the default WAT *.mdf?
ASKER CERTIFIED SOLUTION
Avatar of naspinski
naspinski
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Open the SQL Server Management Studio, connect to the server, open up the databases section, right click on the database and rename.
You could also do it through query analyzer:
http://msdn.microsoft.com/en-us/library/ms186217.aspx
Avatar of hconant

ASKER

Before I play with this, it can't be as simple as changing the aspnetdb.mdf file name, can it?  Naspinski's solution appears to look like it will work, but will the connection string reconfigure itself accordingly just by a rename without the manual rework?
I'm not sure why it won't work if you change the database name by either of the ways mentioned above and modify the connection string, perhaps Naspinski could through some light on this.
By default, all .Net Roles and Users are kept in the ASPNET.mdf file that is referenced by the default connection string that is, for all intents and purposes, hidden (in the machine.config?).

If you want to change where these permissions are held, you simply remove and replace the connectionstring, though the DB must be the *exact* schema of the original file.
Avatar of hconant

ASKER

The nmarun solution didn't work.  Dot net simply created a new ASPNETDB file and looked at that, which was obviously emptly.  Going to play with naspinski's solution now. (actually after breakfast)
Avatar of hconant

ASKER

Houston, we have a problem.  No matter what I do with this so far, .net WAT always recreates a new management db named ASPNETDB.mdf.  I have renamed it, deleted it, changed all the connection strings, blah blah blah.  Interestingly, when I look at the stock .net, after setting up roles and letting it configure its aspnetdb.mdf, I do not find any reference to it (ASPNETDB.mdf) in the web.config file.  I need to find out where the WAT is creating and referencing this file.  To make it simple, how about go back to simply renaming the aspnetdb.mdf and having WAT use it, even on the local SQL server.  I have not even accomplished that yet, and I believe it is the key to the issue.  We can address relocating it later, which I believe can be accomplished via the connection string changes.
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of hconant

ASKER

I've created a new db ASPBIS.mdf which is attached to the hcdesktop\sqlexpress server instance.  I've changed the connection string in the web.config file as shown in the first code snippet below.  I still got this error when trying to run security WAT.
This is the error I got.

The following message may help in diagnosing the problem: An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax. Parameter name: connectionString :

I then changed the connection string to what shows in the second code sample which did work.  I got that code by copying the structure from a working .net WAT.  It would be nice to know why the second code worked, and also since the second code is not what is shown in any of the other samples or tutorials I looked at.  Most signficantly being "AttachDBFilename=|DataDirectory|ASPBIS.mdf" as compared to "="Data Source=hcdesktop2\sqlexpress;initial Catalogue=ASPBIS"

Thanks
rem: CODE THAT DIDN'T WORK
<remove name ="LocalSqlServer" />
		<add name="LocalSqlServer" connectionString="Data Source=hcdesktop2\sqlexpress;initial Catalogue=ASPBIS;Integrated Security=True" providerName="system.data.sqlclient" />
		
			 </connectionStrings>
 
THE FOLLOWING CODE DID WORK, BUT I AM NOT SURE WHY
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|ASPBIS.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
	</connectionStrings>

Open in new window

Avatar of hconant

ASKER

Additional info. The code I used as an example I actually copied from the machine.config file, pasted it into the web.config file, and just simply changed the original ASPNETDB file name with the new ASPBIS db I created and associated with the aspnet_regsql utility.