How do I connect to a database in LabView - sql

I've created a new database using Microsoft SQL Server Management Studio, and now I want to interact with it through LabVIEW. I already have several VIs to interact with a previous database, using the database connectivity tool kit. This database was created by someone who has since left the project and I can't find it in anything but LabVIEW.
I'm quite experienced with LabVIEW, but completely new to and bewildered by databases.
Thank you in advance.

The first Connectivity Toolkit VI called should be Open Connection.
The existing code (VI) will either use a file or a string as an input.
If the input is a string, then you will need to create a new connection string compatible with your server. You can find common SQL Server strings at https://www.connectionstrings.com/sql-server-2008/
If the input is a file name, you can copy the .UDL file that is referenced and then modify the copied file by opening it (double click) and then select the OLE DB Provider for SQL Server and then set the connection options to point to your server, database etc. and then test the connection.

Basically the workflow you have to go through is the following:
Open connection
Execute your query
Fetch data (if needed)
Close connection
If you search for "Database" in the NI Example Finder shipped with Labview you will find a few good starting points.
In particular give a look to Database Connection.vi and Database Fetching.vi.
If you plan to use transactions try also Database Transaction.vi.

I found that the solution to my problem was to create a .udl file and use that as the file path for opening the database connection.
Here's the address that taught me how to do this:
http://msdn.microsoft.com/en-us/library/e38h511e(v=vs.71).aspx
Thank you to everyone who submitted answers, they certainly helped point me in the right direction.

Related

How to set up SQL Export from SCADA

I'm wondering if anyone could point out what this export window (no.3) is trying to ask?
I'm SQL noob and I'm hoping I could get a direction from someone about where to start...
I hope to download data to SQL, basic query and use Python to do more stuff (I'm more familiar with it).
Thank you!
It is a UI of a Universal Data Link (UDL) file on a machine with Windows OS.
First tab contains available installed OLEDB Providers. You need to
select one of them first.
Second, i.e. current tab allows to configure database connection. The 'Test Connection' allows to test that connection.

Microsoft SQL Server connection error with Visual Studio.net (Windows forms)

I've been trying for a while to connect the database to visualstudio.net and it just doesn't work.
First I made the database and made everything I needed there and when I tried connecting it in visual.net through datagridview (trying to get it displayed there) it only gives me access to the "System databases" in which I can't make a database.
After that I decided to make the tables under the "master" database to see if that worked and yeah I can select the database and everything but it says it's empty when I know it's not. It says it has no tables when I've checked multiple times and saw the tables I've created there.
I would appreciate some help to either be able to get for visual to accept a database I make (to be able to automatically detect it once I enter the server name) or to see how can I use the master one properly.
You can add a data source to your project and it will be able to connect to the user databases. Also, it is highly inadvisable to create any user objects in the master database.
master database is a system database and you should not create user objects in the system database. In the connection string, provide the user database name explicitly. If you dont provide the database name, it defaults to master database.
Refer to connection strings for Sql Server for providing the right connection string for SQL Server in .net.

Connection in Paradox Database via ODBC

I've been struggling very hard to make this work. I'm using a software that uses paradox database, which I never used.
My problem is: I can open the program in multiple machines on the same time, but i can't seem to connect via ODBC when there is a program open in any machine (a .lck file maybe?). When noone is using the program I can connect without problems...
I understand that the lock file is there to protect the database integrity, but i wish just to make select commands via SQL directly into it... Is there any way to do it? A read-only connection maybe?
Thanks for the help!!
I had the same problem and I am living with this work around solution on the implementations of software I do where I work.
To make it work:
On the server machine of the paradox database, you have to create a new partition with the same letter where you will map on the client machines;
Share the unit drive;
On the client machines, map a new drive to the shared drive (repeating: the letter must be the same than in the server machine);
Put the database files in this drive;
Create the ODBC paradox system data source (it must be the 32 bit wizard) using the new directory for both Folder and Network folder;
Delete the existing .NET and .LCK before testing;
test...
I've read something about setting AUTO ODBC to TRUE on BDE too...

Lotus Notes ODBC Connection

I need to connect and send/receive information from an MS SQL server in my Lotus Notes app using #formula in realtime (I can connect using an agent, but I need to use inline code for this).
The commands themselves seem pretty straight forward, but setting up the configurations seems to be a topic with scarce documentation. Apparently I need to install an ODBC driver. Where would I find that, and do I install that onto the server or onto the workstations that will run this app?
If any Lotus gurus could step me through setting this up, it would be greatly appreciated.
Thanks
You'll need to install the ODBC driver on the workstations that run this app, if the users will be triggering the ODBC connections. If at all possible, I highly suggest setting this up on the server side, and having it run via an agent. That'll save you from a few headaches, including having to maintain the ODBC connections on each workstation and worrying if each workstation has access to the data and server.
You first just want to make sure your ODBC setup is correct. You'll need the appropriate driver, of course, and the connection information. This site has a walkthrough to give you an idea of how to setup an ODBC database connection
If you have MS Access you can use it to test querying from the ODBC data source. Once you've tested the connection works, you'll just refer to the data source name (DSN) in your #DbColumn, #DbLookup, or #DbCommand formulas.
Back to my suggestion on setting this up on the server side, that would mean you'd keep a copy of the data you're querying within the Notes database itself, and then users would be interacting with read-only data in Notes. You could schedule updates regularly on the server side of that read-only data and effectively create a cache of the data in your Notes environment. Then that data would replicate around to other replicas of the database, but remove the trouble of the ODBC connection being needed everywhere.
If you need realtime data, though, that solution is out the window and you'll have to go with a local solution. In that case, you might want to look at the LCConnection class or using an ADODB.Connection from script, as both will allow you to create DSN-less connections to data sources. You'd then save the trouble of requiring ODBC data sources on each workstation, and only have to worry about whether they can access the server from their workstation.
I would add another option to Ken's list. It involves having the server do the queries of the external database (therefore you are only setting up ODBC in on the server - you don't have to deal with it on the workstations). You create an agent that is launched on the server using the 'run on server' technique. When the workstation needs to query the external data, the code creates a throw-away document in the database, puts the query criteria into the temporary document, saves the document, then calls the 'run on server' agent passing a reference to the temporary document. The server launches the agent, reads the criteria from the temporary document, does the query, and writes the results back to the temporary document. Then the workstation can access the query results from the temporary document. A scheduled agent can delete the temp docs on a regular basis.
It sounds complicated, and it all has to be done in script, but I've done this in many applications and it is fast, flexible, easy to administer, and gives your applications a lot of power. Note that end users must have the ACL rights to create a document in the db (the temp doc) in order for this to work.
Good luck!

Finding The DSN To My Database?

I have an SQL database and want to connect to it using VBA in order to support some legacy functionality. I'm using an ADODB connection and need to know what my database DSN is. How can I find this?
I'm using SQL Server 2008, thanks! :D
A DSN (data source name) is an indirect way of referring to the database. You have to create them manually (or semi-automatically using a wizard of some kind). Go to ControlPanel->AdministrativeTools->DataSources (ODBC) to see if one has already been defined for the database to which you want to connect.
But I think you might mean "connection string", not "DSN". There are many, many ways to tell ADODB how to find and connect to your database (DSNs are just one of those), but you always need a connection string.
I have often turned to ConnectionStrings.com to help me through the maze of similar-but-not-identical options.
There may not be a DSN. DSNs are not created automatically.
I'm not sure you really mean DSN, as a DSN is an ODBC concept. Still, look in Administrative Tools->Data Sources (ODBC).