how to enable role Manager from asp Web Site Administration Tool - asp.net

hi i m trying to enable roles in asp Web Site Administration Tool but when go to the security tab it give me this error
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Unable to connect to SQL Server database.
and i'm using my own connectionStrings to link it to sql server management studio 2012 not to sql CE in the visual studio this is the code
<connectionStrings>
<add name="MusicStoreEntities"
connectionString="Data Source=localhost;
Initial Catalog=Project4DB;
Integrated Security=true;
MultipleActiveResultSets=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
so how can enable roles in this case.

hi i mange to make ASP Web Site Administration Tool security tab work after many searches and hours.
to connect to a regular server management studio 2012 not that one comes with visual studio
first make the following changes in the web.config file :
NOTE: we msut first of all have the database created in the server management studio 2012
1) add your connection string
<connectionStrings>
<add name="MusicStoreEntities" --> change the name to your own connection name
connectionString="Data Source=localhost;
Initial Catalog=Project4DB; --> change it to your one database name
Integrated Security=true;
MultipleActiveResultSets=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
2) in the <system.web> section in the web.config add
<roleManager enabled="false"
cacheRolesInCookie="false"
cookieName=".ASPXROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All"
defaultProvider="AspNetSqlRoleProvider"
createPersistentCookie="false"
maxCachedResults="25">
<providers>
<clear />
<add connectionStringName="MusicStoreEntities" --> change the name to your own connection name
applicationName="/"
name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="AspNetWindowsTokenRoleProvider"
applicationName="/"
type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</roleManager>
and
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="MusicStoreEntities" --> change the name to your own connection name
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
applicationName="/"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""/>
</providers>
</membership>
and
<customErrors mode="Off" />
3) open aspnet_regsql from:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe
and follow the setup wizard
hit next
hit next
choose what database want to connect to then next
and the security tab from ASP Web Site Administration Tool will work to enable the roles.

Related

System.Data.SqlClient.SqlException: Login failed for user 'ASPHOST166\IWAM_plesk(default)'

could anyone help me with this ? Everything works fine in Visual Studio, but does not on a remote server. I have tried to access the page while logged in and logged out, but has got the same error.
Error : "System.Data.SqlClient.SqlException: Login failed for user 'ASPHOST166\IWAM_plesk(default)'."
Web.confing:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=ASPHOST166\SQL2008R2,778; Initial Catalog=Rennoz_DATABASEMDF; User ID=Rennoz_Admin; Password=*****" providerName="System.Data.SqlClient"/>
<add name="ApplicationServices" connectionString="Data Source=ASPHOST166\SQL2008R2,778; Initial Catalog=Rennoz_DATABASEMDF; User ID=Rennoz_Admin; Password=*****" providerName="System.Data.SqlClient" />
<add name="DatabaseEntities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=ASPHOST166\SQL2008R2,778; Initial Catalog=Rennoz_DATABASEMDF; User ID=Rennoz_Admin; Password=*****;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.0">
<assemblies>
<add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
<buildProviders>
<add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />
</buildProviders>
</compilation>
<customErrors mode="Off"></customErrors>
<trace mostRecent="true" enabled="true" requestLimit="1000" pageOutput="false" localOnly="true"/>
<authentication mode="Forms" />
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="ApplicationServices" applicationName="/"
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
<add applicationName="/" name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<location path="Moderation">
<system.web>
<authorization>
<allow roles="Admin" />
<deny users="*" />
</authorization>
</system.web>
</location>
</configuration>
Code behind the page (inserting) :
protected void EntityDataSource1_Inserting1(object sender, EntityDataSourceChangingEventArgs e)
{
Good pic = (Good)e.Entity;
//pic.PhotoAlbumId = photoalbumid;
FileUpload fileupload1 = (FileUpload)ListView1.InsertItem.FindControl("FileUpload1");
string virtualFolder = "~/pics/";
string fizfolder = Server.MapPath(virtualFolder);
string filename = Guid.NewGuid().ToString();
string extension = System.IO.Path.GetExtension(fileupload1.FileName);
fileupload1.SaveAs(System.IO.Path.Combine(fizfolder, filename + extension));
pic.ImageURL = virtualFolder + filename + extension;
pic.Date = System.DateTime.Today;
}
Looks like your application runs under account which is not exist in SQL server. Thus you have login and password specified in connection string for Entity Framework, I think you need remove Integrated Security=True; from this Entity Framework connections string:
<add name="DatabaseEntities"
connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=ASPHOST166\SQL2008R2,778; Initial Catalog=Rennoz_DATABASEMDF; User ID=Rennoz_Admin; Password=*****;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
UPDATE: According to your error message, user instance login flag is not supported on your version of SQL server. So remove also User Instance=True; parameter.
Your DatabaseEntities connection string specifies User ID and Password but also Integrated Security=true (which takes precedence). Remove the latter to use the specified SQL account.
Also remove User Instance=true - it is only used when attaching MDF files dynamically.
I had a similar issue.
I let Plesk handle my connection string and then removed it from my web.config file but that's up to you.
1) I created the user "CT11881\IWAM_plesk(default)" under logins, using Windows Authentication.
2) Granted the user full access in "Server Rolls" and "Securables"
http://forums.asp.net/t/1954164.aspx?Windows+2008+VPS+w+Plesk+11+x+SQL+connection+issues
To have to use IntegratedSecurity if your SQL server is located on different machine, you should run your site under the same credential which are allowed in SQL server.
If your Web machine not in domain, you should create the same user with the same credential on both machines (Web and SQL). In the "SQL Server Management Studio", add this user and set needed priviledges.
In the IIS, go to your application pool, click "Advanced settings" and set credentials (for user which you created or for domain user) in the property "Identity".
In the IIS, in your site, go to "Advanced settings" and set credentials (for user which you created or for domain user) in the property "Physical Path Credentials".
In the "ConnectionString", if you are used "localhost" in the property "source", change it on UNC address, where is located your SQL server.
If connection can't be established, make sure that the TCP/IP protocol is enabled in the "SQL Server Configuration Manager" for used SQL instance (after change, need to restart an instance) and that is TCP port 1443 is alowed in firewall on your SQL machine. You can ping this port from the Web machine with help "Paping" utility - "paping YourSqlMachine -p 1433 -c 4".

ASP.NET Universal Providers 1.2 - "The connection name 'LocalSqlServer' was not found"

I'm trying to use the "ASP.NET Universal Providers 1.2" from http://nuget.org/packages/System.Web.Providers
using Visual Studio 2010 and Sql Server 2008
Everything works find on my local dev box. However, but when I go deploy the code to a DEV server, I get the following error when first hitting the web site (I have code in application start that creates default roles and a default membership user if not existing):
"The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty."
I've created sql script to create the SqlMembershipProvider tables (reversed engineered from a temp database when provider ran corrrectly locally). The correct tables are there and it works just fine using the main sql server instance on my dev box.
I'm unsure why its trying to use the old provider on the remote DEV server. I'm assuming its a permission error. On my dev box, I am an admin and was using integrated security. For the DEV server, I am using a SQL Server account (see connection string below), which as SELECT INSERT UPDATE DELETE perms on each of the SqlMembershipProvider tables. Are there more perms needed for a SQL Server account?
Here is the provider values from web.config
<profile defaultProvider="DefaultProfileProvider" enabled="true">
<providers>
<add name="DefaultProfileProvider"
type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="MasterSqlClientConnectionString" applicationName="PortalDEV"/>
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider"
type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
applicationName="PortalDEV" connectionStringName="MasterSqlClientConnectionString" enablePasswordRetrieval="true" enablePasswordReset="true"
requiresQuestionAndAnswer="true" requiresUniqueEmail="true" maxInvalidPasswordAttempts="3" minRequiredPasswordLength="8"
minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordFormat="Encrypted"/>
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider" enabled="true" cacheRolesInCookie="false" cookiePath="/" cookieProtection="All" cookieRequireSSL="true"
cookieSlidingExpiration="true" cookieTimeout="16" maxCachedResults="25">
<providers>
<add name="DefaultRoleProvider"
type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="MasterSqlClientConnectionString" applicationName="PortalDEV"/>
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider" compressionEnabled="true" timeout="16">
<providers>
<add name="DefaultSessionProvider"
type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</providers>
</sessionState>
And here is my connection string (with data masked):
Any ideas?
The trick was to add a "< clear / >" line at start of section in config file. ASP.NET Universal Providers 1.2 - "The connection name 'LocalSqlServer' was not found"

Can't create asp.net membership database aspnetdb

I can't seem to create the aspnetdb.mdf via the Web Site Administration Tool.
I am using SQL Express 2008 and Visual Studio Web Developer 2010 Express.
I get following error in the Administration Tool:
There is a problem with your selected data store. This can be caused
by an invalid server name or credentials, or by insufficient
permission. It can also be caused by the role manager feature not
being enabled. Click the button below to be redirected to a page where
you can choose a new data store.
The following message may help in diagnosing the problem: An error
occurred during the execution of the SQL file 'InstallCommon.sql'. The
SQL error number is 5170 and the SqlException message is: Cannot
create file 'C:\USERS**\DOCUMENTS\VISUAL STUDIO
2010\WEBSITES\BUGZ-B-GONE\APP_DATA\ASPNETDB_TMP.MDF' because it
already exists. Change the file path or the file name, and retry the
operation. CREATE DATABASE failed. Some file names listed could not be
created. Check related errors. Creating the
ASPNETDB_97c73957a1fb4a189ccca0449aa7d754 database...
I also get this error when I delete the mdf file or change the path.
Underneath is the web.config file:
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
<add name="DATABASEConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DATABASE.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="ApplicationServices" applicationName="/"
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
<add applicationName="/" name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Your error says that the database is already present, so first delete it and then run WSAT. If not works then delete your web.config and add a new config file to your project and then run WSAT and add the aspnetdb database.
Also you can try aspnet_regsql
Path: C:\Windows\Microsoft.NET\Framework\v4.0.30319
Run it, then you can add or remove AspNet database tables from your database.
Read more detail on MSDN

how to change ASP.NET Configuration tool connection string

how can I change ASP.NET Configuration tool-s connection string name?
(Which connection string will ASP.NET Configuration tool will use)
I'm learning ASP.NET and everywhere and in book that I'm reading now theres connection string named: LocalSqlServer.
I want to use my local sql server database instead of sql express to store Roles, Membership and other data.
I have used aspnet_regsql.exe to create needed data structures in my database. after that I changed my web.config to look like:
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Server=(LOCAL); Database=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
but when I run ASP.NET Configuration tool it says that:
"The connection name 'ApplicationServices' was not found in the applications configuration or the connection string is empty."
ASP.NET Configuration tool uses connection string named: ApplicationServices not LocalSqlServer.
cause of that I have to modify web.config to:
<connectionStrings>
<add name="ApplicationServices" connectionString="Server=(LOCAL); Database=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
and everything works fine.
I wish to know why the hell my web site uses connection string named: ApplicationServices and all books and online documentations uses LocalSqlServer? and how to change it to LocalSqlServer?
I have:
Windows 7
Sql Server 2008 R2
Visual Studio 2010 Premium
Project type is website
accidentally I have found my question answer when looking to web.config file.
if you override default machine.config configuration settings in web.config file you can change ASP.NET Configuration tool-s connection string name.
I got my web.config file from book-s code archive and it was the problem.
in web.config u can override which connection string name will be used for: membership, profile and roleManager.
to override membership use:
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/"/>
</providers>
</membership>
where connectionStringName is the name of connection string which will be used for storing membership data.
others are:
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="LocalSqlServer"
applicationName="/"/>
</providers>
</profile>
and
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="LocalSqlServer" applicationName="/"
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
<add applicationName="/" name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>

Trouble with membership providers

I'm having a spot of trouble with ASP.NET 4.0 memberships. I want to have all my membership configuration in my web.config file and not use machine.config. I am storing the membership in a remote SQL Server 2008 R2 database server called MYSERVER\A. Here's the relevant sections of web.config
<connectionStrings>
<clear/>
<add name="MarksDB" connectionString="Server=MYSQLSERVER\A;Database=test_d; Trusted_Connection=Yes; Application Name=MarksDB"/>
</connectionStrings>
<system.web>
<authorization>
<allow roles="Admins" />
<deny users="?" />
</authorization>
<authentication mode="Forms">
<forms name="MarksDB" />
</authentication>
<membership defaultProvider="MarksDBMembershipProvider">
<providers>
<clear/>
<add
name="MarksDBMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="MarksDB"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
applicationName="MarksDBMembershipProvider"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="MarksDBRoleProvider">
<providers>
<clear/>
<add
name="MarksDBRoleProvider"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="MarksDB"
applicationName="MarksDBRoleProvider"
/>
</providers>
</roleManager>
In Visual Studio 2010, when I go to WebSite->ASP.NET Configuration, and click Add User on the Security tab, I get this error:
An error was encountered. Please return to the previous page and try again.
The following message may help in diagnosing the problem: The connection name 'MarksDB' was not found in the applications configuration or the connection string is empty. at System.Web.Util.SecUtility.GetConnectionString(NameValueCollection config) at System.Web.Security.SqlMembershipProvider.Initialize(String name, NameValueCollection config) at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)
I am not sure how to troubleshoot this problem. Any ideas?
You should use the applicationName attribute both in membership provider and in role manager to specify your application (because you could have another application using the same database). But you are specifying the Application Name in the connection string.
I believe you would remove the applicationName from membership provider and from role provider.

Resources