I am migrating a ASP.NET webforms website to a new server. On the old server I had my database in the App_Data folder in the root of the website. On my new server, I have the database in a different folder outside the root and that all works fine.
But something strange happens. When I go to the website and surf around, suddenly a App_Data folder is being created in the root folder of my site with a database in it, called ASPNETDB.MDF. I can delete it but after a while it appears again.
I did some testing and trying, and I found out that the DB is being created when I run this code:
TestLabel.Text = Profile.MyProfileParameter.ToString();
So I think it must be the Profile being called that causes it. In my web.config I have the following: (a bit reduced, i have more profile parameters)
<profile enabled="true">
<properties>
<add name="MyProfileParameter" type="Int32" defaultValue="30"/>
</properties>
</profile>
A bit higher up in my web.config i have the connectionstring that points to the database outside my root folder:
<connectionStrings>
<add name="ConnectionString" providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TheNameOfMyDatase;Integrated Security=True;MultipleActiveResultSets=True" />
</connectionStrings>
Does anybody have any idea why a call to profile would generate a database? It's not a real show stopper, but I'd like to know why this is happening.
Some extra info:
SOLUTION:
Apparently there still a lot for me to learn about web.config.
Apart from the web.config there is also a machine.config from which the web.config inherits.
In this machine config in the section <profile>
there is this setting:
<profile>
<providers>
<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</profile>
This setting can be overridden in the web.config
First (I do not think this is really necessary ) I remove the localSqlServer from the connection strings by adding a clear command to my <connectionStrings>
:
<connectionStrings>
<!-- clear command removes localSqlServer from machine.config -->
<clear />
<add name="ConnectionString" providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TheNameOfMyDatase;Integrated Security=True;MultipleActiveResultSets=True" />
</connectionStrings>
If I run my site now you get an error saying the connection name 'LocalSqlServer' was not found.
So I added a new provider to the <profile>
section and point it to my ConnectionString
<profile enabled="true">
<providers>
<!-- clear command removes localSqlServer from machine.config -->
<clear/>
<add name="AspNetSqlProfileProvider" connectionStringName="ConnectionString" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
Now it all works fine, no more database appearing out of the blue.
Thank you ijaz for giving directions, the bonus is yours!
AspNetdb is a database used by Asp.Net Membership provider or other application services like "profiles,Roles/Rights etc" The generated .mdf file is a database (SQL 2005 express).
It stores the information you store in your profile or membership or roles, when you use the standard sql providers in ASP.NET. App_Data is the default location of this db,but off-course it can be changed. try to find and update the section of web.config file as,
<membership>
<providers>
</providers>
</membership>
for details,please have a look at the following post.
http://forums.asp.net/t/1517995.aspx