Log Onto SQL Server Using Windows NT Authentication

Here is a simple function you can use to connect to SQL Server. This function attempts to connect to the server either using the default SQL Server authentication or Windows NT authentication. If you want to connect to the server using Windows NT authentication, then you can pass “True” for blnUseNTLogin parameter. Internally, this function uses “LoginSecure” property of the SQLDMO.SqlServer object. When “LoginSecure” is set to “True”, any values provided for “Login” and “Password” arguments in the Connect method are ignored.

In order to run this function, you need to add a reference to “Microsoft SQLDMO Object Library” (SQLDMO.RLL) in your VB project. You can find this file in BINNResources1033SQLDMO.RLL under your SQL Server 7.0 directory.

 Private Function LogOnToSqlServer(ByVal strServerName As String, _ByVal strUserID As String, _ByVal strPassword As String, _ByVal blnUseNTLogin As Boolean) As BooleanOn Error GoTo LogOnToSqlServer_ErrorHandlerDim objSQLServer As SQLDMO.SQLServer' Create an instance of SQL Server objectSet objSQLServer = New SQLDMO.SQLServer' If this is true Connect to the SQLServer object uses' Windows NT Authentication ModeobjSQLServer.LoginSecure = blnUseNTLogin' Attempt to establish a connection with the SQL ServerobjSQLServer.Connect strServerName, strUserID, strPassword' Return true as call to Connect passedLogOnToSqlServer = TrueExit FunctionLogOnToSqlServer_ErrorHandler:LogOnToSqlServer = False' Display error messageMsgBox "Error Number = " & Err.Number & ", Description = " & Err.Description, _vbCritical, "SQL Server Error"End Function
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS