[QODBC-Desktop] Connection string for ASP.Net
Posted by brad waddell on 12 March 2009 05:21 PM

How to: Connect to a QODBC Database Using ASP.NET

     You can use the SqlDataSource control to connect to any database that supports Open Database Connectivity (ODBC) by storing connection string information in the Web application's Web. Config the file and then reference the connection string from your SqlDataSource control.

To configure a connection string for ODBC in the Web. config file

     Open the Web. Config file in the root directory of your ASP.NET application. If you do not have a Web. Config file, create one.

     In the Configuration element, add a ConnectionStrings component if one does not already exist.

     Create an added element as a child of the ConnectionStrings component, defining the following attributes:

            name Set the value to the name you want to use to reference the connection string.

            connectionString Assign the connection string required by the database you are connecting to, setting the appropriate driver, server name, and authentication information.

            provider name Assign the value "System.Data.Odbc", which specifies that ASP.NET should use the ADO.NET System.Data.Odbc provider when making a connection with this connection string.

     The connection string configuration will be similar to the following example. In this example, the connection string values to connect to QuickBooks using an ODBC provider.

                connectionString="DRIVER={QODBC Driver for QuickBooks};DFQ=D:Dataem1996.qbw;SERVER=QODBC;UseDCOM=Y;OpenMode=F;"

       Save the Web. Config the file and close it.

To reference the ODBC connection string from a SqlDataSource control

     On the page on which you want to connect to the QODBC database, add a SqlDataSource control.

     In the SqlDataSource control, specify the following properties:

            SelectCommand Set to the query you want to execute for this data control. The syntax of the query depends on the data source you are accessing.

           ConnectionString Set the name of the connection string you created on the Web. Config file.

              ProviderName Set the name of the provider you specified on the Web. Config file for the corresponding connection string.

Note: You can also define UpdateCommand, InsertCommand, and DeleteCommand properties. The SqlDataSource control supports commands and functionality not covered here.

      The following example shows a SqlDataSource control configured to access the QODBC data source. In the example, the SelectCommand property is set to a SQL query.

     SelectCommand="Select * From Customer"
     ConnectionString="<%$ ConnectionStrings:QODBCDataConnectionString %>"
     ProviderName="<%$ ConnectionStrings:QODBCDataConnectionString.ProviderName %>" />

     You can now bind other controls, such as the GridView control, to the SqlDataSource control

Special Notes

     I think it might be worthwhile to make sure that IIS, QODBC, and QuickBooks can all talk to each other first before questioning ASP.NET connection types and strings.

See: How to see QuickBooks data in an Internet Explorer Browser using Windows XP for the IIS/QODBC/QuickBooks setup requirements and a simple web example to test.

(145 vote(s))
Not helpful

Comments (2)
05 August 2013 02:29 AM
connectionstring DFQ=D:Dataem1996.qbw; what meaning?
Rajendra Dewani
21 September 2013 07:35 AM
I am sorry was a typo error, it should be D:\Dataem1996.qbw
we have correct the path issue.

More details on parameters.

DFQ = Path to company file or . (dot) to indicate currently open company file.
OpenMode = F (Follow Company), M (Multi-user), S (Single-user).
DeveloperCode = This is for users of the OEM version only. It is required to connect to the OEM licensing model. The Code is given to you when you purchase an OEM licensing pack.
ColumnNameLen = This is a number that specifies the maximum length a column name can be. Using this is required in some development environments. Its use will make the returned column names not match the normal defined schema.

Example of simple DSN:
sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"

Example of a DSNless connection string:
sConnectString = "Driver={QODBC Driver for QuickBooks};DFQ=C:\Program Files\QODBC Driver for QuickBooks\sample04.qbw;OpenMode=M;OLE DB Services=-2;"

Example using current ADO syntax:
sConnectString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=QuickBooks Data;OLE DB Services=-2;"
Post a new comment
Full Name:
CAPTCHA Verification 
Please complete the captcha below (we use this to prevent automated submissions).