Knowledgebase: Connection
[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 file and then referencing 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 element if one does not already exist.

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

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

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

            providerName 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 are used to connect to QuickBooks by using an ODBC provider.

<configuration>
    <connectionStrings>
         <add
                name="QODBCDataConnectionString"
                connectionString="DRIVER={QODBC Driver for QuickBooks};DFQ=D:Dataem1996.qbw;SERVER=QODBC;UseDCOM=Y;OpenMode=F;"
                providerName="System.Data.Odbc"
         />
     </connectionStrings>
</configuration>

       Save the Web.config file and close it.

To reference the ODBC connection string from a SqlDataSource control

     In the page in 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 that you want to execute for this data control. The syntax of the query depends on the data source you are accessing.

           ConnectionString Set to the name of the connection string that you created in the Web.config file.

              ProviderName Set to the name of the provider that you specified in 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.

<asp:SqlDataSource
     ID="SqlDataSource1"
     Runat="server"
     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 at this point to make sure that IIS, QODBC, and QuickBooks can all talk to each other first before questioning ASP.NET connection types and connection 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.

(144 vote(s))
Helpful
Not helpful

Comments (2)
Richard
05 August 2013 02:29 AM
connectionstring DFQ=D:Dataem1996.qbw; what meaning?
Rajendra Dewani
21 September 2013 07:35 AM
Hi,
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:
Email:
Comments:
CAPTCHA Verification 
 
Please complete the captcha below (we use this to prevent automated submissions).