Error -2147467259 when Connecting to My SQL Server Database Through ActiveX

Updated Jan 10, 2018

Reported In

Software

  • LabVIEW Professional
  • LabVIEW Database Connectivity Toolkit 1.0

Issue Details

I am connecting to an SQL Database using ActiveX from LabVIEW. I also have a UDL file which I know works. However, the connection string I feed into the ADODB._Connection property node does not work. Instead it feeds me the error -2147467259:

Exception occured in Microsoft OLE DB Provider for SQL Server: Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. in DB Connect.vi

My LabVIEW code and connection string look like this:


​What have I done wrong?

Solution

When you create a UDL file from a LabVIEW VI, you would access that from the menu Tools»Create Data Link.... Chosing the Microsoft OLE DB Provider for SQL Server option, you could proceed through the rest of the connection details with the following details:
 
  • Server name = myServer/myInstance
  • User name = myUsername
  • Password = myPassword
  • Allow saving password
  • Database = myDatabase


After clicking OK, you would generate a UDL file, containing the following string:

Provider=SQLOLEDB.1;Password=myPassword;Persist Security Info=True;User ID=myUsername;Initial Catalog=myDatabase;Data Source=myServer\myInstance

We can interpret the string in the following way:
 
  1. Provider=SQLOLEDB.1: The OLE DB provider is "Microsoft OLE DB Provider for SQL Server" 
  2. Password=myPassword: The password is "myPassword" 
  3. Persist Security Info=True: You will allow saving the password (password is saved in the udl file) 
  4. User ID=myUsername: The user name is "myUsername" 
  5. Initial Catalog=myDatabase: The name of the database on the server is "myDatabase" 
  6. Data Source=myServer\myInstance: The server name is "myServer" and the instance name is "myInstance" 
Comparing this string with the one in the connection string in the ActiveX call, we can see that there is an extra string Integrated Security=SSPI. By removing this string, the call to the database should work.

Additional Information

If this for some reason does not resolve the issue, you could also try the following:
 
  1. The message "The login is from an untrusted domain and cannot be used with Windows authentication" indicates that you are logging in from a different domain than the server machine that hosts the SQL Server. In many cases, the SQL Server machine is hosted on the same company domain as the client machines. Try your LabVIEW code from another machine that you know is located on the same domain as the SQL Server.
  2. Ask your IT staff to make your account (that you use to log on to your machine on your domain) a trusted account in the SQL Server. 
  3. Use the Database Connectivity Toolkit API instead. This enables you to call the UDL file directly with the VI "DB Tools Open Connection":

WAS THIS ARTICLE HELPFUL?

Not Helpful