Solved

How to get select rows or columns without using SQL statement

Posted on 2014-12-10
11
246 Views
Last Modified: 2014-12-17
Hi,

I'm trying to get values of a table that's in SQL server.   Currently we use

             
var selectproducts = new List<Product>();
 using (var newdb = new NorthWNDModel())
              {
                  selectproducts = newdb.Products.SqlQuery("dbo.GetProductsByCategory @p0", selectedCategoryID).ToList();
              }

Open in new window


We would like to get the tables without using SQL.   Is this possible?  We are using Entity Frame 6.1 Code First from Database.  If so, could you provide an example?  Thanks.

David
0
Comment
Question by:davidst98
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
11 Comments
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 40493931
Get something from SQL server without using SQL? no, it's not possible by definition. Any tool, wizard, LINQ, etc., would still be a wrapper around some SQL it would generate for the purpose.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40493950
if you refer to stored procedures, the "input" for the tool is then the procedure name, and the sql actually encapsulated into that stored procedure
you may want to move the access to a central web-service platform, which returns the data as needed, and "hiding" the sql there.
0
 
LVL 40
ID: 40494260
As vadimrapp1 told you, there need to be SQL somewhere for anything you want to retrieve from a database.

Guy hinted that you might want to hide the SQL for some reason. If anything else, please tell us why you want to get rid of the SQL statement, and we might be able to help you more precisely.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 40495047
Surely you can retrieve data without SQL...

SQL Server database is a disk file as any other file on your PC, so everything you need is to know the file structure and then some tool which will read data from this structure. You may write such program yourself.

The database structure is described e.g. here:
http://www.practicalsqldba.com/2013/09/sql-server-data-file-structure.html
http://www.pythian.com/blog/analyzing-sql-server-data-file-anatomy/
http://aboutsqlserver.com/tag/internal-structure/
https://www.simple-talk.com/sql/database-administration/sql-server-storage-internals-101/

I am not offering any code because this is not the way how we should use SQL Server data... If you do a regular database backup then the time to restore it is much lower than the time necessary to write a utility which will read the physical database file.

Remember the database file can be encrypted or placed in a cloud. In such case you have a lot of work to obtain readable data this way (comparing to simple backup/restore).
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 40495457
davidst98:

could you please clarify your question with some examples of your quest result?
0
 
LVL 42

Expert Comment

by:pcelba
ID: 40498464
Unbelievable :-)
Am I the only one who knows gurus reading or even fixing MS SQL .mdf files in hexa editor?
0
 
LVL 40
ID: 40498470
It's not that it is completely impossible. After all, as pcelba stated, is a disk file as any other file on your PC.

But trying to work directly on the file is a hack that is a pain to do. One has to be crazy or going after a lot of money to want to access SQL Server data without going through the server... thus SQL Statements.

This reminds me of hacks we did in the 80's because systems were slow and reading the disks directly enables us to improve the speed a little bit. You have no ideas how many disks were scrapped because a bit was written in the wrong place. Disks held only 350K of data, so where not too much trouble to recreate. But recreating a 10Gb database from scratch, that would not please your boss or your Customer. And many databases are much larger that that.

And the hack is impossible most of the time anyway, because the typical SQL Server database is on 24/24 and the file itself is thus locked for any process that does not go to the server, when they are not encrypted. I do not have the time to read them, but I suspect that the web pages referenced in the winning question assume that the server is down.
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 40498502
"One of my favorite Real Programmers was a systems programmer for Texas Instruments. One day, he got a long distance call from a user whose system had crashed in the middle of saving some important work. Jim was able to repair the damage over the phone, getting the user to toggle in disk I/O instructions at the front panel, repairing system tables in hex, reading register contents back over the phone. The moral of this story: while a Real Programmer usually includes a keypunch and line printer in his toolkit, he can get along with just a front panel and a telephone in emergencies."

"Real Programmers Don't Use Pascal", DataMation, 1983

> And the hack is impossible most of the time anyway,

I suspect, even more important is that all this is about 10 light years away from what the author meant when he asked how to avoid SQL.
0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question