Back to
Latest changes:

This is an old revision of the document!


Using MS SQL instead Access in WebDemo sample project

Here you will find the detailed instructions how to modify our sample applications (WebDemoCS or WebDemoAjaxCS) to make it work with SQL Server instead of Access.

1. Change the following line in using section of Default.aspx.cs file:

using System.Data.OleDb;

to

using System.Data.SqlClient;

2. After that change the type of your DbConnection object. Just search for all inclusions of DbConnection variable and change it's declaration if necessary. You will need to change the connection string accordingly.

Here is the new code:

private System.Data.SqlClient.SqlConnection DbConnection = null;
    . . . . . .
DbConnection = new SqlConnection();
DbConnection.ConnectionString = "Data Source=DEVPC1\\SQLEXPRESS;Initial Catalog=nwind;Integrated
Security=True";

3. Then change the type of OleDbDataAdapter to SqlDataAdapter in QueryPanel1_SqlExecute and other methods where it exists. For example the following line of code:

OleDbDataAdapter resultDA = new OleDbDataAdapter(e.SQL, DbConnection);

should be replaced with:

SqlDataAdapter resultDA = new SqlDataAdapter(e.SQL, DbConnection);

4. Find the following line of code in your Default.aspx.cs file:

query.Formats.SetDefaultFormats(FormatType.MsAccess);

and replace it to this one:

query.Formats.SetDefaultFormats(FormatType.MsAccess);

5. Finally you will need to change <asp:AccessDataSource …> tag in Default.aspx file to SqlDataSource. Here is an example how it may look like:

<asp:SqlDataSource ID="ResultDS" runat="server" ConnectionString="Data Source=DEVPC1\SQLEXPRESS;Initial
Catalog=nwind;Integrated Security=True"></asp:SqlDataSource>

Discussion

, 2014/10/08 09:14
Hi,

I want to use my Sql server Database instead of the access database.
I did the modification as suggested above.
But still the Dbquery query is using NWind.xml file to create the DBMOdel.
Kindly guide how to generate the Model using the sql server database.

Thanks,
Krupa
, 2014/11/10 19:38
That's because there is still a piece of code which loads "NWind" model.
Something like
''model.LoadFromFile(appDataPath + "NWind.xml");''

You need to create your own model file (as it's described here: http://docs.korzh.com/easyquery/data-model-editor/creating-new-data-model) and place new XML file into App_Data folder of your project. Let's guess that new file is "MyModel.xml"
The you have to change that piece of code to something like:
''model.LoadFromFile(appDataPath + "MyModel.xml");''
, 2015/10/13 01:52
Getting Error The name 'e' does not exist in the current context for #3 above
, 2015/10/13 12:47
You don't need to add that line somewhere. You just need to modify the existing one (for example in QueryPanel1_SqlExecute method).
So if previous line has that ''e'' parameter then it must be recognized in new one as well.
Enter your comment: