Thursday, February 9, 2012

Access denied on deployment

Just deployed my web app at an ISP. The very first time I hit my database, I get an exception

'SQL Server does not exist or access denied'

I'm trying to connect using an SQL account with user id and password (which work fine if I go in using SQL Query Analyser).

The connection string contains the initial catalog, user id and password.

Can anybody help please?

Thanks,
BernieI assume you checked the remote data source address too.

Did you try connecting to the remote database using the Server Explorer inside of VS.Net? If you can connect to it through there, then just drag a table from the remote data source onto some test page. Look in the VS.Net generated code in the code behind and find where it creates the connection. Copy and paste this connection string info to where you need it.|||Are you sure you're using the correct server in the connection string?

When I first started doing this, in SQL Client Network Utitlity, I gave my server an Alias - - locally, that's what I was using, and when I uploaded the pages to the server, I'd forget to change the alias, and of course, it wouldn't work, since the host has no idea what that alias is.|||Thanks for the replies guys. I did as McMurdoStation suggested.
I could 'see' the server database and all of its tables from the VS.Net SQL server , so proceeded to create an SQL Adaptor/SQL Connection datagrid etc... on a test page.

When it tried to connect, the login failed, so I assume this is the same problem.

The connection string looks like:-
value="initial catalog=ClubNoticeBoard; user id=ClubNoticeBoard;pwd=*****;packet size=4096"

The one in the test page I created looks like
this.sqlConnection1.ConnectionString = "workstation id=BERNIE;packet size=4096;user id=ClubNoticeBoard;data source=\"URL here\";persist security info=False;initial catalog=ClubNoticeBoard";

I've just read somewhere that the ASPNET account must have access, that sounds reasobale as I can access the database fine except through the aspx pages. How do I go about setting up an ASPNET account using the SQL Server Enterprise Manager.

Cheers,
Bernie|||under SQL Server explorer, expand on the name of your database, right click on 'Users' and click on 'Add New Database user'. then add ASPNET user.

HTH.|||Ok, bearing in mind that this is a shared server at an ISP, when i did what you suggested, I get the New User box up requesting a Login name and User name. The Login name is a drop down list of other logins that already exist, plus BUILTINS\Administrators.

What do I select in that login box, I can type in ASPNET but it then gives me an error saying 'login doesn't exist'.

Assuming I can eventually get a Login of ASPNET what would I put in the User name.

Cheers,
Bernie|||I think the database user is a red herring, as my local development machine does not have an ASPNET user.

Although there is an ASPNET account for the machine itself, and so I suspect that this is what I need. I have asked the ISP to set one up.

Cheers,
bernie|||you have to select <new> from the list and then it will let you add a new user.|||I tried that but it said I had to be an adminsitrator to complete the task.

Can somebody tell me what exactly needs to be setup on the box?

1. Is it a new user account i.e machinename/ASPNET?
2. Is it a new SQL Server log with name ASPNET?

If no. 1, what happens about the password, how can asp.net use it if doesn't know it?
If no. 2, would it use WIndows Authentication, or an SQL account?

I must say this all seems pretty standard stuff, I can't understand why nobody has come up with a definitive answer. Maybe the ISP i'm using don't know their ASP.NET stuff and they havn't set things up correctly.

Cheers,
Bernie|||when you install vs.net it creates a ASP.NET user account on your system. this is for internet users to login to your comp. but for the aspx pages to access your databases, you still need to add the machinename\ASPNET account inside the SQL Server.

when you select <new> user from the list, another window will come up to fill in the details for the new user.

there would be a button with "..." on it which will bring up all the user accounts on that computer. click on it and you can choose the ASPNET account from the list.
and you can use windows authentication. and dont forget to choose the database.

we usually need not set a password. you can use integrated security in your connection string. something like this :

"server=local;database=Northwind;Integrated Security=SSPI "

and i guess you need to be an admin to create a user account in SQL Server.

HTH|||Thanks, the problem was I couldn't see ASPNET in the drop down list.

All sorted now and working (up to a point), I've some other permission issues to sort out.

Thanks everybody for your help.

Bernie

No comments:

Post a Comment