Monday, February 13, 2012

AD/ SQL Server 2000/ Trusted Connection in .Net

Hi,
I have a Windows Application, a Novell Network and a SQL Server 2000 on an
Active Directory controlled server. My AD account has access to teh database
.
I want to login to the database using an Active Directory account, trusted
security...but I can't.
Sequence of Events:
1. Login to Network using Novell account.
2. Start Application and it displays login screen.
3. Enter AD account details and press OK
4. This verifies against Active Directory Account using the following code:
visual basic
code:----
-- Public Function Login() As String
' now create the directory entry to establish connection
Dim deDirEntry As New DirectoryEntry(Me.strDomain, Me.strUser,
Me.strPass, Me.atAuthentType)
Try
' if user is verified then it will welcome then
Try
Return deDirEntry.Username
Catch exp As Exception
Return ""
End Try
Finally
'deDirEntry.Dispose()
End Try
End Function 'Login
----
--
This all works fine and returns the username if the credentials match
5. Make database connection string (sUserName is the AD username):
visual basic
code:----
--Dim
sConnstring As String = "User ID=" & sUserName & ";Initial
Catalog=VendorSample;Data
Source=MyServer...;Timeout=20;Trusted_Connection=True"--
----
6. I get the following error:
Login failed for user '(null)'. Reason: Not associated witha trusted SQl
Server connection.
I'm not well up on how AD works etc. but does anybody have any idea how to
get past this? I presume the problem is that it is not recognising the
username passed as the account I want to use.There are two ways to logging into SQL Server: WIndows Security
(Trusted_Connection) or SQL Server Security. In either case, your "Login"
function is useless.
In your connectionString, you have "Trusted_Connection=True", that implies
the SQL Server uses Windows security, meaning, you do not need pass
username/password pair in ConnectionString (even there is user/password,
they are ignored). That means SQL Server accept the current windows/AD user
account credential, and then does the authorization based on this
credential. As long as the the windows/AD user account (which is running
your app) is given adequate permission to what he needs, the app should run
fine.
If you use SQL Server security (it must be enabled), you must have
user/password pair in the ConnectionString, and SQL Server authenticates it,
regardless whether you have done it in your own "Login" function or not. SO,
your "Login" function does nothing usefull here.
"Dec" <Dec@.discussions.microsoft.com> wrote in message
news:E608FA02-488A-4E9A-BC5B-9AF816F28F87@.microsoft.com...
> Hi,
> I have a Windows Application, a Novell Network and a SQL Server 2000 on an
> Active Directory controlled server. My AD account has access to teh
> database.
> I want to login to the database using an Active Directory account, trusted
> security...but I can't.
> Sequence of Events:
> 1. Login to Network using Novell account.
> 2. Start Application and it displays login screen.
> 3. Enter AD account details and press OK
> 4. This verifies against Active Directory Account using the following
> code:
>
> visual basic
> code:---
--
> Public Function Login() As String
> ' now create the directory entry to establish connection
> Dim deDirEntry As New DirectoryEntry(Me.strDomain, Me.strUser,
> Me.strPass, Me.atAuthentType)
> Try
> ' if user is verified then it will welcome then
> Try
> Return deDirEntry.Username
> Catch exp As Exception
> Return ""
> End Try
> Finally
> 'deDirEntry.Dispose()
> End Try
> End Function 'Login
> ----
--
> This all works fine and returns the username if the credentials match
> 5. Make database connection string (sUserName is the AD username):
> visual basic
> code:---
--Dim
> sConnstring As String = "User ID=" & sUserName & ";Initial
> Catalog=VendorSample;Data
> Source=MyServer...;Timeout=20;Trusted_Connection=True"--
----
> 6. I get the following error:
> Login failed for user '(null)'. Reason: Not associated witha trusted SQl
> Server connection.
> I'm not well up on how AD works etc. but does anybody have any idea how to
> get past this? I presume the problem is that it is not recognising the
> username passed as the account I want to use.|||Hi,
If I have logged onto pc/ network using a windows account, will the app
always run using this account? If so, is there any way to change this so tha
t
the app run using an AD account instead? As you've probably guesed, I'm not
well up on Windows/ AD accounts etc. so please explain in very simple terms!
!
Thanks.
"Norman Yuan" wrote:

> There are two ways to logging into SQL Server: WIndows Security
> (Trusted_Connection) or SQL Server Security. In either case, your "Login"
> function is useless.
> In your connectionString, you have "Trusted_Connection=True", that implies
> the SQL Server uses Windows security, meaning, you do not need pass
> username/password pair in ConnectionString (even there is user/password,
> they are ignored). That means SQL Server accept the current windows/AD use
r
> account credential, and then does the authorization based on this
> credential. As long as the the windows/AD user account (which is running
> your app) is given adequate permission to what he needs, the app should ru
n
> fine.
> If you use SQL Server security (it must be enabled), you must have
> user/password pair in the ConnectionString, and SQL Server authenticates i
t,
> regardless whether you have done it in your own "Login" function or not. S
O,
> your "Login" function does nothing usefull here.
>
> "Dec" <Dec@.discussions.microsoft.com> wrote in message
> news:E608FA02-488A-4E9A-BC5B-9AF816F28F87@.microsoft.com...
>
>

No comments:

Post a Comment