FactoryTalk View SE Visual Basic to connect to SQL server

I am trying to get a local instance of FT View SE to connect to a local SQL database for some stored recipe information. All of this was backed up and restored from an older computer and I have had to put things back together piecemeal. This was all made by another company and for the recipe screen they used entirely VBA script to connect to the DB and pull the information for display. I have restored the DB with the same name, set up the same users, and they were using an ini file to store login and path info and then loading that into variables in the VBA script so that has been updated too. If there is some other connection that needs to be made, I'm not experienced enough to know what it needs to be. Anyone have any experience they can lend?
 
If they were using an ODBC DSN you will need to set that up on the PC too. Usally one would use a connection made in the VBA code.
Here is one from an old project. It uses SQL OLE DB connection and does not require an ODBC setup:

Public Const strCnn As String = "Provider=SQLOLEDB;Data Source=192.168.1.200;Initial Catalog=plantdata;UID=plantuser;PWD=plantuser;"

If it used a local system DSN using ODBC then it would look more like:
Public Const strCnn As String = "DSN=LocalDSNName;Data Source=192.168.1.200;Initial Catalog=plantdata;UID=plantuser;PWD=plantuser;"
 
Yes, I am seeing a connection string in the VBA code, with variables being used to fill in the connection info. The variables are being fed from an INI file in the project folder. The data source is using localhost instead of an IP, I don't know if that matters for a SQL server being hosted on the same PC running the HMI client. I need to go back and check the ODBC admin console just to see if the drivers for the SQL server version are installed, SQLNCLI10.1.

.ConnectionString = "Provider=SQLNCLI10.1;password =" & pPassoword & ";user ID=" & pUser & ";initial catalog=" & pDB & ";data source=" & pService
 
What's annoying is that I can create a new .udl file on the desktop and enter the same connection information and get a successful test connection to the database.
 
Does the DSN connection work when you test connection? If you are using a DSN then the connection info is contained within it.

Something like this.

string dsnName = "DSN=MyDSN";
using (OdbcConnection conn = new OdbcConnection(dsnName))
{
conn.Open();
}
 
I eventually figured this out. The connection strings were correct, but the function being called to open and read the INI that they were storing the login info in was failing for some reason. They didn't have any checks or error handling written in to catch that so I never realized it was happening outside of getting a message for "invalid authorization specification" once I started adding error handling.

So the connection string information was never getting loaded and was just blank. I removed the INI section and just hardcoded the connection info and everything is working now. Thanks for everyone's help.
 

Similar Topics

Hello, Im trying to learn how to use VBA with factorytalk view so i can later design displays using tags from PLCs and im having some trouble...
2
Replies
4,783
Views
Good morning! I've run into a stopping point with a Visual Basic task on a View Studio SE project and was wondering if anyone could point me in...
3
Replies
28,633
Views
Hello All, I am having some issues in FactoryTalk View Studio V15 where I am unable to open a couple tabs in the explorer window. Currently, it...
15
Replies
456
Views
Hi, I am starting up a FTView SE V16 project which we are planning to use to replace an older version of FTView SE. In the Diagnostics SQL tables...
0
Replies
146
Views
Customer is running FTView network distributed v12. I've had datalogs running for a few years and the data goes to a remote SQL server using a...
0
Replies
131
Views
Top