Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 12, 2013 05:19 AM by ToughMan
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.
Dec 14, 2012 07:24 AM|LINK
M. Scott Blalock
"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.
<remove name="YourSqlServer" />
<add name="YourSqlServer" connectionString="server=.\sqlexpress;database=OA;Integrated Security=SSPI"/>
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!
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!
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
(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.
Jan 12, 2013 05:19 AM|LINK
U can mark urself an answer.