Groups | Blog | Home
all groups > c# > march 2005 >

c# : Sql connection and web services


xxxxyz NO[at]SPAM abv.bg
3/23/2005 11:46:12 PM
Hi,

I want to connect to Sql Server using SqlConnection class using Web
service. I use users from Sql server (I create this users in Sql
Server). And I want to have a sql connection for every connected user
with their user name and password.

How can I organise these connections?
And how use them?

Thanks.
Dan Bass
3/24/2005 3:46:12 PM
Presumably, an extension of this scenario is that your users would be
calling the web service, which would in turn use their user name and
password for access to the SQL Server database.

I'd recommend calling each method, where the user name and password are
passed into the web service. A connection is created and used locally within
that method only. (no session state connections)

The method would essentially:
- construct a connection string form the username and password passed in
- opens the database connection
- pushes or pulls data from the database with this connection
- close the connection again.

The connection string template should be stored in the web configuration
file.

The fact you're having passwords passed to you means you should also use a
secure connection (HTTPS).

Hope that helps.

Daniel.

[quoted text, click to view]

xxxxyz NO[at]SPAM abv.bg
3/25/2005 3:21:47 AM
Thanks.

I would like to know if there is any possility for using sessions?
Peter Bromberg [C# MVP]
3/25/2005 10:21:31 PM
You can use the Session object in an ASP.NET - hosted webservice. Didn't see
the beginning of this post thread, but we should mention that keeping a
connection is session is never a good idea.
Peter

[quoted text, click to view]

AddThis Social Bookmark Button