locked
How access the SQL server data directly from a silverlight web part? RRS feed

  • Question

  • Hi,

    What is the best practice for accessing the SQL server data directly from a silverlight web part in sharepoint 2010. Can you please provide the links for the sample implementations if any?

    Thank you.


    Facimus
    Tuesday, July 19, 2011 12:31 PM

Answers

  • System.Data.SQLClient is not part of the SilverLight Runtime. You will have to create and call a service (or similar) to get the data from the SQL Server.

    If you would like to access data from the content database you could use the Client OM.

     

     

    • Proposed as answer by Ryan T Mann Tuesday, July 19, 2011 1:56 PM
    • Marked as answer by Facimus Tuesday, July 19, 2011 6:49 PM
    Tuesday, July 19, 2011 12:52 PM
  • Build a WCF WebService on the server that allows you to get what you want using System.Data.SQLClient.  E.g. you can create a service that takes a query and returns an XML node array of the results.

    In the method, filter out any query commands you want to block, implement an authentication system, etc whatever you want to do to make it secure.  Then you can consume that WCF Service in the silverlight APP using .Net Framework,

    You might even want to develop specific methods that are designed to do something more specific.

    E.g., instead of building a webservice that lets you query the whole DB, Create methods to query specific tables.

     

    E.g.

    MyCompany.WCFClient client = new MyCompany.WCFClient;

    int[] productIDs = client.Tables.Product.GetProductIDs(); //REturns an array of integers where each integer is the ID of a product in the product table.

    foreach (int productID in productIDs)

    {

        //client.Tables.Product.GetProductInfo(productID);

    }

    Then consume your services in SilverLight.

    A quick google results in a video on consuming WCF Services in silverlight.

    http://www.silverlight.net/learn/videos/all/how-to-consume-wcf-and-aspnet-web-services-in-silverlight/


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction
    • Marked as answer by Facimus Tuesday, July 19, 2011 6:49 PM
    Tuesday, July 19, 2011 2:02 PM

All replies

  • What SQL server data are you trying to access directly? LOB system data? If you are trying to access SharePoint data then you should use the object model or look into creating a BDC model using Business Connectivity Services.
    Tuesday, July 19, 2011 12:37 PM
  • Hi,

    I am talkin about querying and getting SQL server data directly in a silverlight web part. I dont want to access sharepoint data or use BCS services for LOB data.

    thank you

     


    Facimus
    Tuesday, July 19, 2011 12:43 PM
  • System.Data.SQLClient is not part of the SilverLight Runtime. You will have to create and call a service (or similar) to get the data from the SQL Server.

    If you would like to access data from the content database you could use the Client OM.

     

     

    • Proposed as answer by Ryan T Mann Tuesday, July 19, 2011 1:56 PM
    • Marked as answer by Facimus Tuesday, July 19, 2011 6:49 PM
    Tuesday, July 19, 2011 12:52 PM
  • Build a WCF WebService on the server that allows you to get what you want using System.Data.SQLClient.  E.g. you can create a service that takes a query and returns an XML node array of the results.

    In the method, filter out any query commands you want to block, implement an authentication system, etc whatever you want to do to make it secure.  Then you can consume that WCF Service in the silverlight APP using .Net Framework,

    You might even want to develop specific methods that are designed to do something more specific.

    E.g., instead of building a webservice that lets you query the whole DB, Create methods to query specific tables.

     

    E.g.

    MyCompany.WCFClient client = new MyCompany.WCFClient;

    int[] productIDs = client.Tables.Product.GetProductIDs(); //REturns an array of integers where each integer is the ID of a product in the product table.

    foreach (int productID in productIDs)

    {

        //client.Tables.Product.GetProductInfo(productID);

    }

    Then consume your services in SilverLight.

    A quick google results in a video on consuming WCF Services in silverlight.

    http://www.silverlight.net/learn/videos/all/how-to-consume-wcf-and-aspnet-web-services-in-silverlight/


    My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction
    • Marked as answer by Facimus Tuesday, July 19, 2011 6:49 PM
    Tuesday, July 19, 2011 2:02 PM