Wait... before you paste the standard FAQ for this question...
My WebForms application works fine! I even created a fresh WebForms Project which works fine!
In both applications I can create and use users and roles in the application and within the ASP.Net Admin Tool running against the local aspnet.mdf or against a SQL Express instance I created using aspnet_regsql tool. All is well and I should just accept
that everything works... EXCEPT....
EVERYTHING seems to work fine except the Test functionality under the Provider tab in the ASP.NET Web Config Tool. The fact that it gives me the
"Could not establish a connection to the database. If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line
utility to create and configure the database, and then return to this tool to set the provider. "
just makes me wonder why. If I create an new WebForms Application using the default local ASPNet Security DB, should not the AspNet Web Config tool connect to the provider correctly with no changes? Everything works, so I assume the generated security must
be configured correctly. Why the error?
So to reproduce this this was my steps:
1). In VS2012 create New Project - Webforms / VB.Net / Create Solution
2). In New Project Goto Project ASP.Net Config
3). Enable Roles Under Security in the ASPNet Web Tool
4). Click Test Under Provider Tab in the ASPNet Web Tool
5). Observe error
The Test Application works, I can register as a new user, I can create roles using the admin tool, I can put my user in a role and I can access a webpage using the role. It all works except the error message in the Provider Tab. Why?
"Could not establish a connection to the database. If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility
to create and configure the database, and then return to this tool to set the provider. "
I can't reproduce your issue locally. In order to resolve your issue, please check the connection string is correct. Please configure it in your web.config.
"Could not establish a connection to the database. If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility
to create and configure the database, and then return to this tool to set the provider. "
Check ur db can meet the AspnetMember class defined since asp 2.0.
And u should run the aspnet_regsql command to generate the tables!
The original issue as described above by Scott is REAL....It's a Sunday afternoon and I am trying to set up a critical new project in VS2012 using an existing membership database and I am ready to pick up my development system and toss it out the window...
Before I describe any additional details, let me say that I have been developing in .net for a decade, I have been using SQL server for the same period of time, I have been using ASP.NET Membership for the last 3 years and have multiple websites and membership-enabled
SQL databases that run just fine.
When I create a new project in VS2012 (web, 4.5, C#, ASP.NET Web Forms Application,), the new project/application is created.
Sometimes a .mdf file will be created in App_Data, sometimes (more often) not.
In the Web.Config file, the expected and necessary entries will be created -- except when the .mdf membership db/file is not created then no connection string is created either.
When the default .mdf membership db is created and I try to use it as Scott describes above (config the Provider information in the ASP.NET Configuration tool), I will receive the very same message about "Could not establish a connection to the database.......etc.".
This is after making absolutely zero changes to the generated code, project structure, web.config, etc.
Whether or not the .mdf membership db is created, if I add (or switch to) a connection string (even using the same "DefaultConnection" connection string name) that specifies one of my existing working SQL Server databases that contain the Membership infomation,
I also receive the same error message.
If I run an existing 4.0 web forms application under VS2012 pointing at exactly the same existing SQL Server databases that contain membership data, the ASP.NET Configuration tool works just fine and I can configure the Provider, the Security, etc.
There does appear to be a REAL issue here that deserves explanation or attention. Scott is describing the issue accurately as am I. It is extremely frustrating. How are we supposed to develop applications and move them into production when we can't even
get the membership security functions to work?
OK, after spending more time on this issue this afternoon, I now have a new VS2012 web application under 4.5 where the ASP.NET Configuration tool works fine.
The problem is in the four (4) related sections of settings in the main web.config file of the application.
Whether or not the default .mdf membership database is created in the App_Data folder, the various settings in the web.config file will contain references to the file
ANDto the DefaultMembershipProvider. This (the DefaultMembershipProvider) appears to be the problem, along with the references to the .mdf file whether it is created or not.
One additional symptom of this issue...I did discover one additional symptom of this problem while finding the resolution. When the various settings in the web.config file are setup incorrectly, the ASP.NET Configuration page will take a long time to come
up. It will also take a long time to change from page to page. This is evidently due to the timeout that you have to wait to occur when it can't find the desired membership database.
The steps I took to correct the problem -- all of these changes are made to the main web.config file....
(1) the Connection String. I changed the name from DefaultConnection to anything else. This isn't necessary but I did so I was certain the site would be looking for the correct connection string elsewhere in the .config file. I also used a valid and tested
connection string.
(2) In the Membership Providers section of the web.config file, you must change the NAME of the provider, change the TYPE of the provider, and make certain the conntectionStringName is set to your connectionstring's name.
<div> <membership></div> <div> <providers></div> <div> <clear/></div> <div> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" </div> <div> connectionStringName="ApplicationServices" enablePasswordRetrieval="false" </div>
<div> enablePasswordReset="true" requiresQuestionAndAnswer="false" </div> <div> requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" </div> <div> minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" </div>
<div> passwordAttemptWindow="10" applicationName="/"/></div> <div> </providers></div> <div> </membership></div> <div></div> <div>(3) In the Profile Providers section of the web.config file, you must change the NAME, TYPE, and connectionStringName
as well.</div> <div></div> <div> <div> <profile></div> <div> <providers></div> <div> <clear/></div> <div> <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/></div>
<div> </providers></div> <div> </profile></div> </div> <div></div> <div>(4) In the RoleManager Providers section of the web.config file, you must change the NAME, TYPE, and connectionStringName as above. I also went ahead and pasted in a second line
(AspNetWindowsTokenRoleProvider) that was used in other pre-VS2012/4.5 applications.</div> <div></div> <div> <div> <roleManager enabled="true"></div> <div> <providers></div> <div> <clear/></div> <div> <add name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/></div> <div> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/></div> <div>
</providers></div> <div> </roleManager></div> </div> <div></div> <div>Once I made these changes, the ASP.NET Configuration came up quickly and performed as it should have.</div> <div></div> <div>Good luck to anyone encountering this issue. The default
values entered into the web.config file are not conducive to using previously created ASP.NET Membership-enabled databases.</div> <div></div> <div>Lynn</div>
M. Scott Bla...
0 Points
10 Posts
Web Site Admin Tool VS2012 Local or SQLExpress
Dec 12, 2012 04:02 PM|LINK
Wait... before you paste the standard FAQ for this question...
My WebForms application works fine! I even created a fresh WebForms Project which works fine!
In both applications I can create and use users and roles in the application and within the ASP.Net Admin Tool running against the local aspnet.mdf or against a SQL Express instance I created using aspnet_regsql tool. All is well and I should just accept that everything works... EXCEPT....
EVERYTHING seems to work fine except the Test functionality under the Provider tab in the ASP.NET Web Config Tool. The fact that it gives me the
"Could not establish a connection to the database. If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider. "
just makes me wonder why. If I create an new WebForms Application using the default local ASPNet Security DB, should not the AspNet Web Config tool connect to the provider correctly with no changes? Everything works, so I assume the generated security must be configured correctly. Why the error?
So to reproduce this this was my steps:
1). In VS2012 create New Project - Webforms / VB.Net / Create Solution
2). In New Project Goto Project ASP.Net Config
3). Enable Roles Under Security in the ASPNet Web Tool
4). Click Test Under Provider Tab in the ASPNet Web Tool
5). Observe error
The Test Application works, I can register as a new user, I can create roles using the admin tool, I can put my user in a role and I can access a webpage using the role. It all works except the error message in the Provider Tab. Why?
Thanks for the help.
Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: Web Site Admin Tool VS2012 Local or SQLExpress
Dec 14, 2012 07:24 AM|LINK
Hi,
I can't reproduce your issue locally. In order to resolve your issue, please check the connection string is correct. Please configure it in your web.config.
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
ToughMan
Participant
1490 Points
635 Posts
Re: Web Site Admin Tool VS2012 Local or SQLExpress
Dec 16, 2012 07:23 AM|LINK
Check ur db can meet the AspnetMember class defined since asp 2.0.
And u should run the aspnet_regsql command to generate the tables!
LLahman
Member
38 Points
41 Posts
Re: Web Site Admin Tool VS2012 Local or SQLExpress
Jan 06, 2013 07:34 PM|LINK
The original issue as described above by Scott is REAL....It's a Sunday afternoon and I am trying to set up a critical new project in VS2012 using an existing membership database and I am ready to pick up my development system and toss it out the window...
Before I describe any additional details, let me say that I have been developing in .net for a decade, I have been using SQL server for the same period of time, I have been using ASP.NET Membership for the last 3 years and have multiple websites and membership-enabled SQL databases that run just fine.
When I create a new project in VS2012 (web, 4.5, C#, ASP.NET Web Forms Application,), the new project/application is created.
Sometimes a .mdf file will be created in App_Data, sometimes (more often) not.
In the Web.Config file, the expected and necessary entries will be created -- except when the .mdf membership db/file is not created then no connection string is created either.
When the default .mdf membership db is created and I try to use it as Scott describes above (config the Provider information in the ASP.NET Configuration tool), I will receive the very same message about "Could not establish a connection to the database.......etc.". This is after making absolutely zero changes to the generated code, project structure, web.config, etc.
Whether or not the .mdf membership db is created, if I add (or switch to) a connection string (even using the same "DefaultConnection" connection string name) that specifies one of my existing working SQL Server databases that contain the Membership infomation, I also receive the same error message.
If I run an existing 4.0 web forms application under VS2012 pointing at exactly the same existing SQL Server databases that contain membership data, the ASP.NET Configuration tool works just fine and I can configure the Provider, the Security, etc.
There does appear to be a REAL issue here that deserves explanation or attention. Scott is describing the issue accurately as am I. It is extremely frustrating. How are we supposed to develop applications and move them into production when we can't even get the membership security functions to work?
Help -- please and thank you!
Lynn
LLahman
Member
38 Points
41 Posts
Re: Web Site Admin Tool VS2012 Local or SQLExpress
Jan 06, 2013 08:31 PM|LINK
OK, after spending more time on this issue this afternoon, I now have a new VS2012 web application under 4.5 where the ASP.NET Configuration tool works fine.
The problem is in the four (4) related sections of settings in the main web.config file of the application.
Whether or not the default .mdf membership database is created in the App_Data folder, the various settings in the web.config file will contain references to the file AND to the DefaultMembershipProvider. This (the DefaultMembershipProvider) appears to be the problem, along with the references to the .mdf file whether it is created or not.
One additional symptom of this issue...I did discover one additional symptom of this problem while finding the resolution. When the various settings in the web.config file are setup incorrectly, the ASP.NET Configuration page will take a long time to come up. It will also take a long time to change from page to page. This is evidently due to the timeout that you have to wait to occur when it can't find the desired membership database.
The steps I took to correct the problem -- all of these changes are made to the main web.config file....
(1) the Connection String. I changed the name from DefaultConnection to anything else. This isn't necessary but I did so I was certain the site would be looking for the correct connection string elsewhere in the .config file. I also used a valid and tested connection string.
<div><connectionStrings></div> <div> <add name="ApplicationServices" connectionString="Initial Catalog=aaaaaaaa;Data Source=bbbbbbb;Persist Security Info=False;user id=cccccccc;password=dddddddd;" providerName="System.Data.SqlClient" /></div> <div> </connectionStrings></div>(2) In the Membership Providers section of the web.config file, you must change the NAME of the provider, change the TYPE of the provider, and make certain the conntectionStringName is set to your connectionstring's name.
<div> <membership></div> <div> <providers></div> <div> <clear/></div> <div> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" </div> <div> connectionStringName="ApplicationServices" enablePasswordRetrieval="false" </div> <div> enablePasswordReset="true" requiresQuestionAndAnswer="false" </div> <div> requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" </div> <div> minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" </div> <div> passwordAttemptWindow="10" applicationName="/"/></div> <div> </providers></div> <div> </membership></div> <div></div> <div>(3) In the Profile Providers section of the web.config file, you must change the NAME, TYPE, and connectionStringName as well.</div> <div></div> <div> <div> <profile></div> <div> <providers></div> <div> <clear/></div> <div> <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/></div> <div> </providers></div> <div> </profile></div> </div> <div></div> <div>(4) In the RoleManager Providers section of the web.config file, you must change the NAME, TYPE, and connectionStringName as above. I also went ahead and pasted in a second line (AspNetWindowsTokenRoleProvider) that was used in other pre-VS2012/4.5 applications.</div> <div></div> <div> <div> <roleManager enabled="true"></div> <div> <providers></div> <div> <clear/></div> <div> <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/></div> <div> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/></div> <div> </providers></div> <div> </roleManager></div> </div> <div></div> <div>Once I made these changes, the ASP.NET Configuration came up quickly and performed as it should have.</div> <div></div> <div>Good luck to anyone encountering this issue. The default values entered into the web.config file are not conducive to using previously created ASP.NET Membership-enabled databases.</div> <div></div> <div>Lynn</div>ToughMan
Participant
1490 Points
635 Posts
Re: Web Site Admin Tool VS2012 Local or SQLExpress
Jan 12, 2013 05:19 AM|LINK
U can mark urself an answer.