Author Topic: Connect to Microsoft SQL Database  (Read 3526 times)

marco.fuhrmann

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 6
    • View Profile
Connect to Microsoft SQL Database
« on: February 25, 2016, 03:20:02 pm »
I want to use pqgrid in a c# .net-application.
I didn`t found a way to connect to a MS SQL Database in the Demos (for example Remote Paging). Where I have to configure the connection to the Database(s)?

Normally i use something like this:

Code: [Select]
string source = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=c:\x\x\documents\visual studio 2013\Projects\WebApplication3\WebApplication3\App_Data\Product.mdf;Integrated Security=True";
SqlConnection conn = new SqlConnection(source);
conn.Open();

greetings,
marco.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Connect to Microsoft SQL Database
« Reply #1 on: February 25, 2016, 10:58:44 pm »
The connection string can be defined in web.config

Code: [Select]
<configuration>
  <connectionStrings>     
      <add name="pqTestContext" connectionString="data source=localhost;Integrated Security=false;Initial Catalog=x;UID=y;password=z" providerName="System.Data.SqlClient" />
  </connectionStrings>
.....
.....
</configuration>

Entity framework is used for database connectivity.

Code: [Select]
//name of class is same as connection string.
public class pqTestContext : DbContext
{
        public DbSet<Invoice> Invoices { get; set; }
        public DbSet<Product> Products { get; set; }
        public DbSet<Company> Companies { get; set; }
}

In the remote paging demo, pqTestContext refers implicitly to database connection.

Code: [Select]
  pqTestContext db = new pqTestContext();

and then LINQ is used.

Code: [Select]
var orders = (from order in db.Invoices
                        orderby order.OrderID
                        select order).Skip(skip).Take(pq_rPP);
« Last Edit: February 26, 2016, 09:09:30 am by paramquery »

marco.fuhrmann

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Connect to Microsoft SQL Database
« Reply #2 on: February 26, 2016, 03:14:02 pm »
Is there a ParamQuery Grid Tutorial for ASP .NET available (like the php-tutorial) where I can see, how  the "Controller"-class or the "DbContext"-class in the remote paging demo are working?
Normally i use pqgrid only to show the query results from MS SQL or ORACLE-databases. Now I try to use it to edit the the database entries too.

jenson

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Connect to Microsoft SQL Database
« Reply #3 on: March 06, 2017, 08:43:33 am »
Hi,

I'm also interested to get a sample on ASP.NET Webform instead of PHP demo/samples.

Thanks.

Regards,
Jenson