Saturday, February 25, 2012

Cannot connect via Web Application...

I am using SQLServer 2000, Visual Studio 2003, C#.
I am writing a web part which requires me to connect to a local sql
database.
I wrote a class which handles the connection and reading of the table.
When I try to call .Open on the connection, it fails, the exception is
something to do with permission.
I used the same class to connect with a console application and a
windows application, and it works fine. I am able to connect and read
the table.
Can anyone shed some light on what is the difference between
connecting/accessing to a database via Web Application as opposed to a
Non-Web App.
TIAI think your problem has something to do with permission as the error
indicates. If you are writing an ASP.Net web page then your web application
is running as the ASPUSER Windows user and chances are this use does not
have permissions to connect to the database. When you run as a Windows
application you run as you and you probably have admin permissions on the
box which gives you SA permissions in the database so you can do whatever
you want. Confirm that you are running as ASPUSER and then create a login
and user for it in SQL Server.
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"IV" <Imtiaz.Vohra@.vtechsr.com> wrote in message
news:1168476873.734347.313800@.k58g2000hse.googlegroups.com...
>I am using SQLServer 2000, Visual Studio 2003, C#.
> I am writing a web part which requires me to connect to a local sql
> database.
> I wrote a class which handles the connection and reading of the table.
> When I try to call .Open on the connection, it fails, the exception is
> something to do with permission.
> I used the same class to connect with a console application and a
> windows application, and it works fine. I am able to connect and read
> the table.
> Can anyone shed some light on what is the difference between
> connecting/accessing to a database via Web Application as opposed to a
> Non-Web App.
> TIA
>|||Roger,
Thanks for the reply.
I ran SQL Server Enterprise Manager and for that database, I checked
the Users.
there are two, dbo and guest, both having full permissions.
How would I confirm tthat I am running as ASPUSER and create a login
for it?
Thanks,
IV
Roger Wolter[MSFT] wrote:[vbcol=seagreen]
> I think your problem has something to do with permission as the error
> indicates. If you are writing an ASP.Net web page then your web applicati
on
> is running as the ASPUSER Windows user and chances are this use does not
> have permissions to connect to the database. When you run as a Windows
> application you run as you and you probably have admin permissions on the
> box which gives you SA permissions in the database so you can do whatever
> you want. Confirm that you are running as ASPUSER and then create a login
> and user for it in SQL Server.
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> "IV" <Imtiaz.Vohra@.vtechsr.com> wrote in message
> news:1168476873.734347.313800@.k58g2000hse.googlegroups.com...|||Log in as an admin. USE the database where your tables are and execute
these commands (substituting the name of you machine for servername)
CREATE LOGIN [servername\ASPNET] FROM WINDOWS
CREATE USER [servername\ASPNET] FROM LOGIN [servername\ASPNET]
http://msdn2.microsoft.com/en-us/library/ms189751.aspx
http://msdn2.microsoft.com/en-us/library/ms173463.aspx
You will then have to grant this user access to the objects it needs to
access for your application
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"IV" <Imtiaz.Vohra@.vtechsr.com> wrote in message
news:1168487427.667116.147270@.p59g2000hsd.googlegroups.com...
> Roger,
> Thanks for the reply.
> I ran SQL Server Enterprise Manager and for that database, I checked
> the Users.
> there are two, dbo and guest, both having full permissions.
> How would I confirm tthat I am running as ASPUSER and create a login
> for it?
> Thanks,
> IV
> Roger Wolter[MSFT] wrote:
>|||Roger,
I appreciate you taking the time to help me out.
I tried what you said and am still failing with the same exception.
Imtiaz
Roger Wolter[MSFT] wrote:[vbcol=seagreen]
> Log in as an admin. USE the database where your tables are and execute
> these commands (substituting the name of you machine for servername)
> CREATE LOGIN [servername\ASPNET] FROM WINDOWS
> CREATE USER [servername\ASPNET] FROM LOGIN [servername\ASPNET]
> http://msdn2.microsoft.com/en-us/library/ms189751.aspx
> http://msdn2.microsoft.com/en-us/library/ms173463.aspx
> You will then have to grant this user access to the objects it needs to
> access for your application
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> "IV" <Imtiaz.Vohra@.vtechsr.com> wrote in message
> news:1168487427.667116.147270@.p59g2000hsd.googlegroups.com...

No comments:

Post a Comment