[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:
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.
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.
You can now bind other controls, such as the GridView control, to the SqlDataSource control
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.