Friday, February 24, 2012

Connection string problem

Hi

I am manually able to create a connection to my db in the vs2005 ide using
Tools->Connect to Database. In the connection I see 'Data
Source=MYSERVER;Initial Catalog=aspnetdb;Integrated Security=True' as the
connection string and 'NET Framework Data Provider for SQL Server' as the
provider. Following these settings in my code and I have used the connection
string;

<add name="Membership" connectionString="Data Source=MYSERVER;Initial
Catalog=aspnetdb;Integrated Security=True"
providerName="System.Data.SqlClient"/
in my app's web.config file. This connection is then used by a custom
membership provider for the create user wizard. Now when I try to create a
new user in the wizard I get the following error;

System.Data.SqlClient.SqlException: Cannot open database "aspnetdb"
requested by the login. The login failed.
Login failed for user 'MYSERVER\ASPNET'.

I was able to work fine when the db was on sql express. What is the problem
and how can I fix it?

Thanks

RegardsJust allow the aspnet user permissions over the db or specify a user. Its because the aspnet user doesnt have permissions to thedb. The connection string is fine. The easiest way is just tospecify a user and give it permission. This way its more secureanyway.|||

The problem is that the asp.net web application is running as an anonymous user, and you haven't given database access to that account (MYSERVER\ASPNET). When you do it in the IDE, it's using your user access right (MYSERVER\YOU).

A bunch of ways to fix it. Run the asp.net app as you is one way (not recommended). Grant access to the myserver\aspnet user is the better approach. Create him a log in to the sql server, grant him access to the database, and give him enough rights to do what you need to do from the web.

|||

How do you grant access myserver\aspnet user?

Thanks

|||It's quite easy.

My instruction is based on SQL Server 2000:

In Enterprise Manager:

1. Right click on the ASPNET account. (I assume you can do this!)
2. Click on the "Database tab"
3. In the database section (immediately below), place a tick in thecheckbox to the left of the database, if you want ASPNET to access thisdatabase.

Exit the dialog boxes.

If you are using stored procedures, you will need to grant EXEC access.

In Enterpise Manager:

1. Right click on the stored procedure.
2. Choose "properties"
3. Choose "permissions"
4. For "public", check the "Exec" column.

Do for all stored procedures.

No comments:

Post a Comment