This is an old revision of the document!
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
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
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");''
So if previous line has that ''e'' parameter then it must be recognized in new one as well.