This question comes up a lot on the Forums:
"I have a SQL Server
database residing on my PC. I can successfully query tables in this database
from a .Net WinForm. However, if I attempt to perform the same queries using a
.Net WebForm, I get a login failed error message. What's up with that?"
It has to do with permissions. Your WinForm runs as YOU, or I should say as the
user account that you logged into windows as (which, if you are like most people, that
is either Administrator or equivalent). By default SQL Server(MSDE) sets up
a login BUILTIN\Administrators that is in the System Administrator server role.
So, indirectly your windows user has sa rights to SQL (when you use
windows authentication), so does your WinForms app.
WebForms are run by
the asp.net worker process. This process is set up to run as the ASPNET user or
(NT Authority\Network Server on 2003). This user is not by default in the local
machine admin group, which means it doesn't have sa rights to SQL Server.
So, you have to go into your SQL Server, create a login that grants
localmachinedomain\ASPNET user rights to either the db in question, or on your
test machine you can put this sql user into the System Administrator domain.
Another approach would be to put the ASPNET user into the local machine
Administrator group.
Finally instead of using trusted connection in your
connection string you could use a SQL Server account/password. A lot of devs use
sa while developing.
from a solution provided by Bob Archer in Message #949387
|