Windows Authentication

Windows Authentication

Post by Bob » Tue, 22 Oct 2002 02:49:46



We have a client who would like our application, which is written using
ADO.Net and uses Windows Authentication, to detect an authentication failure
and prompt for the user to enter a domain username and password and retry the
connection using that information.

Can anyone give me an idea how I would go about doing that?

Thanks,

Bob

 
 
 

Windows Authentication

Post by Dejan Sark » Tue, 22 Oct 2002 09:45:48


Bob,

Use structured error handling block (Try...Catch...Finally), example in
VB.NET (change the example according to your needs):

Try
cnNorthwind1.ConnectionString = _
"Data Source=" & Me.txtServer.Text & ";" & _
"Initial Catalog=" & Me.txtSQLDatabase.Text & ";" & _
"Integrated Security=SSPI;" & _
"Connection Timeout=" & txtTimeout.Text & ";"
cnNorthwind1.Open()
'Change the dbcontext to get the 5701 Info message
cnNorthwind1.ChangeDatabase("pubs")
Catch XcpSQL As System.Data.SqlClient.SqlException
Dim sErrorMsg As String
Dim se As System.Data.SqlClient.SqlError
For Each se In XcpSQL.Errors
Select Case se.Number
Case 17
sErrorMsg = "Wrong or missing server!"
Case 4060
sErrorMsg = "Wrong or missing database!"
Case 18456
sErrorMsg = "Wrong or missing user/password!"
Case Else
sErrorMsg = se.Message
End Select
lblErrInfo.Text = lblErrInfo.Text & vbCrLf & _
"Sql Error " & se.Number.ToString & " : " & se.Message
Next
Catch XcpInvOp As System.InvalidOperationException
MessageBox.Show("Close the connection first!", _
"Invalid operation", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch Xcp As System.Exception
MessageBox.Show(Xcp.Message, "Unexpected Exception!", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
lblErrInfo.Text = lblErrInfo.Text & vbCrLf & _
"Finally executed."
cnNorthwind1.Close()
End Try

--
Dejan Sarka, SQL Server MVP
FAQ from Neil & others at: http://www.sqlserverfaq.com
Please reply only to the newsgroups.
PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


Quote:> We have a client who would like our application, which is written using
> ADO.Net and uses Windows Authentication, to detect an authentication
failure
> and prompt for the user to enter a domain username and password and retry
the
> connection using that information.

> Can anyone give me an idea how I would go about doing that?

> Thanks,

> Bob


 
 
 

1. SQL Server Authentication vs. Windows Authentication

Hi all,

I am installing MS Project Server 2002 on SQL Server 2000
machine running Win2000.... but I don't know whether I
should use Windows vs. SQL Server authentication? I
couldn't find any book/document that is more specific
about this.. I would appreciate anyone who can help me
please!! If you could please directly send me an email at

Thank you
Delphin

2. AP File Maintenance

3. attempts to logon using SQL Server authentication treated as Windows authentication

4. Viewing the Transaction Log.

5. Windows Authentication and SQl authentication

6. rollback segment

7. SQL Server Windows Authentication : How to connect a different user then the current Windows login user

8. Passing Data Parameters for Store Proc

9. please Help-changed from mixed windows authentication tho windows only locked out

10. Windows Authentication Only -- How to?

11. Windows authentication on SQL Server 2000

12. SQL / Windows Authentication

13. Windows authentication vs Mixed mode!??!