Jane wang Jane wang - 8 months ago 61
C# Question

Check if a user has access to SQL instance

We need to validate if the user has the access to the SQL Server after the username and password are given. However, it is only for Window's login so SQL login can't apply. The user is not necessary the user currently logged in to the window so the Window's connection string won't work also.

Thought about querying the login name in the master database. What would be the syntax to do this?

Answer Source

Not really sure what you are asking but are you saying you have an application and from that application you want to see if a given username matches to a sql login?

If that is the case it is simple to look at sys.sql_logins. Something like this.

[code] select * from sys.sql_logins where name = @name [/code]