Log Onto SQL Server Using Windows NT Authentication

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several