Saturday, December 6, 2014

Learn Querying SQL Server using LINQ - Part 1

The easiest way to do this is to use the popular tool, LINQPAD. It is a great tool
and you can download a free version here:
http://www.linqpad.net/

If you want a brief intro to LINQ review this link:
http://hodentekhelp.blogspot.com/2014/12/what-is-linq.html

In this post we will see how to connect to the SQL Server on your Computer. LINQPAD does a lot more than querying, but for now let us limit ourselves to the immediate task.

Download LINQPAD. It is somewhat like WYSIWYG. You create the query or an expression in LINQPAD and the click of a button executes the query/expression/statement etc. LINQPAD brings the whole of .NET Framework to a very easy interface where you interact. It is also a small program and does not slowdown whatever you are doing.

The specifics of connecting to SQL Server

Download LINQPAD and launch the program which typially opens up as shown (don't be
disappointed at this minimal screen, lot more hides behind).


Now click on Add Connection in the top left pane. The Choose Data Context window
is displayed as shown.
 
 
Of the two panes, let us concern ourselves with the top panel. Assume the Default(LINQ to SQL). Click Next. The LINQ to SQL Connection window is displayed as shown.
 


In the Provider field you have various radio button options and you can connect tot SQL Server, two versions of SQL Compact Edition and SQL Azure. Accept the default SQL Server and that is what this post is about.
  • Since our SQL Server Instance name is Hodentek8\RegencyPark enter this here.(SQL Server 2012)
  • Log on details default is OK because that is what we chose during installation.
  • Also accept that we want to display all in a tree-view
  • For specifying new or existing database, choose Specify new or existing database and click on the drop-down to reveal the databases on the local instance as shown.

 
Choose Adventureworks2012. .Well, well you could include production data.
Now the LINQPAD4 interface changes as shown. Accept all other fields and click the Test button.
You should get a connection successful message as shown.

 
Click OK. Well the LINQPAD4 is  now connected to SQL Server 2012 instance on your computer.



In the next post we look at how to use this tool.
Learn querying SQL Server here:
http://hodentekmsss.blogspot.com/2014/12/learn-querying-sql-server-2012-using.html

 

1 comment:

SQL Server 2025 ready to go

 I have not yet done looking at SQL Server 2022, SQL Server 2025 is ready to go. Microsoft is indeed relentless!  Microsoft announced SQL Se...