By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,011 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,011 IT Pros & Developers. It's quick & easy.

problem with system stored procedure in Linq

P: 57
Hi all,

I have to use some of the system stored procedures in link but when i click on system stored procedure in my database explorer. it does not display me the list of system stored procedure?? cant we use system stored procedure in link?

can someone suggest me a solution

Regards,
Vineet
Mar 3 '09 #1
Share this Question
Share on Google+
9 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Have you seen this blog on using stored procedures in linq?
Mar 5 '09 #2

P: 57
The problem is not that "i can not use stored procedures". I can use userdefined stored procedure. the problem is when i go to Database Explorer in my Visual Studio and click on Stored Procedure. It does'nt shows me the list of system stored proc. It just shows me the list of User Defined Stored Proc.

I am not able to understant why? so for example if i want to use sp_helpserver(a system defined stored procedure which gives you a list of Linked remote Objects(Remote serveres connected to your server.)) it does not shows me this stored procedure in the list anywhere?

Why?
Mar 7 '09 #3

P: 1
You can call system stored procedures by using _dataContext.ExecuteQuery<Type>(string query, params object[] parameters) function. Just set the query to be the system stored proc you want. Type is the type returned by the query.
The problem is that you have to create the return type yourself, and the names of the properties of this object must be the same as the names of the columns in the result of the query in order for linq to map the result to the return type.

ex:
Expand|Select|Wrap|Line Numbers
  1. class ServerDetails
  2. {  public string name;
  3.    public string network_name;
  4.    public string status;
  5. }
  6.  
  7. using (DataContext dc = new DataContext(cs))
  8. {
  9.    List<ServerDetails> list = dc.ExecuteQuery<ServerDetails>("sp_helpserver").ToList();
  10. }
Aug 10 '09 #4

P: 57
Tnx a lot, it was really helpful
Aug 10 '09 #5

P: 4
Hi

Im also trying to use system stored procedures but i get the error "The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content." i am trying to use the "sp_databases" to retrieve the databases on a server. im i supposed to specify the server and if so where/how??

Thanks!
Sep 28 '09 #6

Frinavale
Expert Mod 5K+
P: 9,731
What have you done to get that error?

You have to specify a data source for the GridView to display. Once you've specified the data source, you need to call the databind method to bind the GridView to the data in order to display the data and work with it. I would recommend specifying the data source and binding it in the PreRender event in order to avoid problems with editing etc.

-Frinny
Sep 28 '09 #7

P: 4
this is the code i used:
Expand|Select|Wrap|Line Numbers
  1.  Using dc As New northwindDataContext
  2.             GridView1.DataSource = dc.ExecuteQuery(Of ServerDetails)("sp_databases").ToList()
  3.             GridView1.DataBind()
  4.   End Using
the error comes up when i try to bind the data to my grid. looks like it is because my datasource is empty. What is it that i am doing wrong? My code is heavily based on the reply by nirosoful but in VB.net
Sep 29 '09 #8

Frinavale
Expert Mod 5K+
P: 9,731
I'm not entirely sure what you're trying to do in that code.

Check out this tutorial on Link to SQL: Retrieving Data Using Stored Procedures. I think it will clarify a few things...


-Frinny
Sep 29 '09 #9

P: 4
that was my first stop when i started using stored procedures. the thing is you can't access system stored procs like that. if you execute the procedure "sp_databases" it will give you all the databases on a server, the size of each and the remarks if any.
Sep 29 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.