ASP.Net Membership SQL Server - asp.net

I've just run the aspnet_regsql tool and setup aspnetdb on a test server. I've setup the Membership stuff in web.config, and I'm trying to administer it via "Project -> ASP.net Configuration" menu item in Visual Studio 2008.
The first few pages pull up just fine -- the default page and the security page. It shows me that I have 0 users and 0 roles. I was able to click on "Enable Role Manager" or whatever it said. In my connection string I'm connecting as the sa user.
When I click on "Create or Manage Roles" I get an error: "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible." etc, about how the server may not be reachable.
Well, I think it is able to get to the server since it shows me that I have 0 users and roles. If it was unable to get there, in past experience, it would show blank instead of 0.
I know that there are many stored procs and functions installed in SQL to support membership, so is it possible that the sa user doesn't have the rights to execute these things? How would I check? I'm really not good at SQL security, as is evidenced by me using the SA username and password.
Any ideas?

according to my experience this thing is impossible. but if you insist on it you can check it your self .
check that sa user have the ASPNETDB owner privilege(by default sa user have all database owner privilege)
good luck dude

http://forums.asp.net/t/978442.aspx/1
Most of the way down the page, here is the code you need to have in your web.config
<roleManager enabled="true" defaultProvider="SqlRoleProvider">
<providers>
<clear/>
<add name="SqlRoleProvider" applicationName="TestItAll" connectionStringName="aspnetdbConnectionString" type="System.Web.Security.SqlRoleProvider"/>
</providers>
</roleManager>

Related

Cannot open database "name" requested by the login. The login failed

I have deployed my web app on a server and I am trying to connect to a database on localdb. I am getting this error.
Cannot open database "hands.mdf" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.
I have created 'IIS APPPOOL\DefaultAppPool' login on the SQL server and given it access to all possible roles under user mapping.
This is my connection string:
<add name="constr" connectionString="Data Source=np:\\.\pipe\LOCALDB#D3DF8A08\tsql\query;Initial Catalog=hands.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
I have looked at similar requests and followed the advice with no luck. I have tried to change
"integrated security" to User ID=domain\administrator;pwd=password"
But still no luck.
Can someone help me with getting this working please?
Maybe 'IIS APPPOOL\DefaultAppPool' doesn't have permission to access hands.mdf directory.
All sorted problem was very simple at the end.
My original connection string was connecting to a local file i.e.
AttachDbFilename=hands.mdf
So when I changed to a attached SQL file
Initial Catalog=hands I should have removed (.mdf)

Unable to connect to SQL Server database with studio express 2012 for web

I cannot connect to SQL Server database.
When I run the aspnet_regsql.exe utility, I get the following error message:
Setup failed.
Exception:
Unable to connect to SQL Server database.
Details of failure
System.Web.HttpException: Unable to connect to SQL Server database. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Also, I am unable to use the ASP.NET Website Administration Tool. When I click on the Security tab I receive the following 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.
So, I click on the 'Choose Data Store' button as instructed, which allows me to select a a Provider. The provider is named 'AspNetSqlProvider', it has a Test link beside it. I click on Test and receive the following error message:
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 have lost overtime for this problem, but i cannot fix it. I hope everybody can help me.
I look forward receive the good answer as soon as possible. Sincerely thanking you very much for your help.
I encounter the same problem in my ASP.NET MVC project as you, when using the ASP.NET Website Administration Tool. The solution is to check and modify your web.config file. I just change the following attributes (add a field):
1) from
<profile>
<providers>...</providers>
to
<profile defaultProvider="DefaultProfileProvider">
<providers>...</providers>
2) from
<membership>
<providers>...</providers>
to
<membership defaultProvider="DefaultMembershipProvider">
<providers>...</providers>
3) from
<roleManager>
<providers>...</providers>
to
<roleManager defaultProvider="DefaultRoleProvider">
<providers>...</providers>
And, be sure to have something like:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication1-20160111151822;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication1-20160111151822.mdf" />
</connectionStrings>
and the "DefaultConnection" has a corresponding field connectionStringName="DefaultConnection" under <profile>,<memebership>and <roleManager> tags, which are modified as stated above.
If you still have problems in your MVC project, just create a new full ASP.NET MVC Web Application template, compare the web.config file with yours, and modify your web.config file.

Failed to generate a user instance of SQL Server due to failure in retrieving the user's local ap

This is my first time to deploy an asp.net web site. Everything is working fine on my local computer but when i published the web site on a remote computer i get the error "Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed"
(only in pages that try to access the database)
Help pleaseee
In IIS under Vista/Windows 7/Server 2008 OS,
Select the application pool and then "advanced settings." Under "process model" find "Load User Profile" and set it to true.
SQL should now load under the default app pool account.
Try the following:
Start IIS
Open Application Pools by clicking on it
Right click on DefaultAppPool and select “Select Application Pool
Defaults”
Change “Identity” property to “NetworkService”
Save and exit IIS
You have to adjust your connection string according to your hosting server.
Modify the below section of web.config according to SQL server user name and password
<connectionStrings>
<add name="DBName" providerName="System.Data.SqlClient"
connectionString="uid=; pwd=; database=; server=;"/>
</connectionStrings>

Why is ASP.NET ignoring my Membership connection string?

I have an ASP.NET app using built-in Membership functionality. As such, I have a connection string in my web.config that looks like this:
<add name="MembershipSqlServer" connectionString="Data Source=servername;Database=aspnetdb;uid=user;pwd=password;" />
When working on my dev machine, everything is peachy keen. But when I move things to the web server (which also happens to run the SQL Server), I get this error when User.IsInRole() is called:
System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
F$%*&!! Why is it attempting to connect in this way? Why isn't it using user/password from the connection string? Web.config is identical on dev and server, I am using the DB on the server during development.
OK, I figured it out... only 35 minutes. :P
Long story short: There are two parts to asp.net membership… a membership provider and a ROLE provider. Why you’d ever want these two things separated, I don’t know… But my web.config wasn’t specifying the role provider and connection string, so it was defaulting to the settings in machine.config (aka LocalSqlServer connection string).
So all this time, my app users were on the server... but the roles were stored in a local .MDF file in App_Data. Ugh.
What does the membership providers section in your web.config look like? Is it possible that you left out the connectionStringName attribute? In which case, I believe it would be trying to connect to the database on your local machine using integrated security.
The membership providers section in your web.config should look something like:
<membership defaultProvider="SqlProvider">
<providers>
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MembershipSqlServer"
...
/>
</providers>
</membership>
Do you see this <authentication mode="Windows" /> in your web.config? And your other connectionString uses Integrated Security=True; On your Sql server in order to use windows authentication you must have a Login(on the server) for the windows user or group as well as have an associated user in the database.
The simple but not suggested fix would be to create a login for 'NT AUTHORITY\NETWORK SERVICE'
on you sql server and then a user in your specific database for that maps to that login.
The secure way is to do this for each of the network security groups that need to access the sql server so you can manage the group permissions independently.
i think the answer is that :
public static string ConnectionString(SPSite site)
{
var connectionStringField = BaseMembershipProvider(site).GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
if (connectionStringField != null)
{
return connectionStringField.GetValue(BaseMembershipProvider(site)).ToString();
}
else
{
return "";
}
}
it worked for me with out any Error
thanks babania

SQL Express connection string hell ASP.Net

SQL Express 2005 is running locally. I have a project written by another person running on the same machine. All I want to do is connect to it, can't be that hard right?
This is the one I use in my old classic ASP code to hit another database running on the same instance:
Provider=SQLOLEDB;Data Source=MYLAPTOP\MSSMLBIZ;Persist Security Info=True;User ID=TestUser;Password=letmein;Initial Catalog=TestDB
But trying a version of that makes the .net code throw a wobbler as he's written it using SQLServer drivers so its not liking the Provider stuff.
Here is the orginal connection string from his code:
Server=(local);Initial Catalog=TheDatabase;User Id=TheUser;Password=ThePassword;
I've been to http://www.connectionstrings.com/sql-server-2005 and tried several of the options from there, these all get "SQL Server does not exist or access denied" (what a lovely mixed error message that is!):
Data Source=localhost;Integrated Security=True;Initial Catalog=TheDatabase
Data Source=localhost\SQLEXPRESS;Integrated Security=True;Initial Catalog=TheDatabase
Data Source=MyLaptop\SQLEXPRESS;Integrated Security=True;Initial Catalog=TheDatabase
Server=MyLaptop\SQLEXPRESS;Initial Catalog=TheDatabase;User Id=TheUser;Password=ThePassword;
I've created logins for MyLaptop/IUSR_MyLaptop, MyLaptop/ASPNET, MyLaptop/IWAM_MyLaptop in SQL Express and given them all read/write permissions to my DB and set their default DB to be TheDatabase.
What the heck am I doing wrong and how can I debug the problem some more?
UPDATE: Special Thanks to Chris for all his pointers, got there in the end, if you are having similar problem please read all the comments there are lots of links and tips on how to track them down.
Can you advise exactly what is in the config?
Are you using the block - in which case a valid connection string would be:
<add name="connection" providerName="System.Data.SqlClient" connectionString="Data Source=localhost\MSSMLBIZ;Initial Catalog=TheDatabase;Integrated Security=True" />
or
<add name="connection" providerName="System.Data.SqlClient" connectionString="Data Source=localhost\MSSMLBIZ;Initial Catalog=TheDatabase;Integrated Security=False;User Id=TheUser;Password=ThePassword;Application Name=AppName;" />
Or are you getting the connection string from app settings - in which case I guess your provider is set in code inside the app itself?
With that error message in your comment you should run through the items in http://blogs.msdn.com/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
I presume the instance is running and does allow connections over tcpip?
Shouldn't your datasource read: Data Source=localhost\sqlexpress too?
You don't mention granting rights for 'TheUser' to access the database on the server - if you're restored from another server you may had a sid mismatch.
Try running
sp_update_users_login 'report'
against the db in question.
If it returns the user account in the report try:
sp_update_users_login 'update_one', 'theuser', 'theuser'
to remap things.

Resources