Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Connecting to SQL Server database in XBAP application [modified]

Connecting to SQL Server database in XBAP application [modified]

Scheduled Pinned Locked Moved WPF
helpdatabasecsharphtmlsharepoint
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Neeraj Kr
    wrote on last edited by
    #1

    Hi I am a beginner in the .Net 3.5. I am making a XBAP application and trying to declare the connection string in the app.config file. When i am using the same in my code I am receiving an unexpected error: Cannot create instance of 'Page1' defined in assembly 'WpfBrowserApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Page1.xaml' Line 1 Position 7. I am using the following in the code behind:

    string conn = ConfigurationSettings.AppSettings["ConnectionString"].ToString();
    DataSet dsEmployees = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "sp_fetchEmployees");
    lstEmployees.DataContext = dsEmployees;

    Kindly help as I am stuck completely

    -----Have A Nice Day-----

    modified on Friday, March 13, 2009 11:16 AM

    A E 2 Replies Last reply
    0
    • N Neeraj Kr

      Hi I am a beginner in the .Net 3.5. I am making a XBAP application and trying to declare the connection string in the app.config file. When i am using the same in my code I am receiving an unexpected error: Cannot create instance of 'Page1' defined in assembly 'WpfBrowserApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Page1.xaml' Line 1 Position 7. I am using the following in the code behind:

      string conn = ConfigurationSettings.AppSettings["ConnectionString"].ToString();
      DataSet dsEmployees = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "sp_fetchEmployees");
      lstEmployees.DataContext = dsEmployees;

      Kindly help as I am stuck completely

      -----Have A Nice Day-----

      modified on Friday, March 13, 2009 11:16 AM

      A Offline
      A Offline
      ABitSmart
      wrote on last edited by
      #2

      ConfigurationSettings.AppSettings is now obsolete. See here MSDN[^]. Instead use ConfigurationManager[^]/WebConfigurationManager as recommended. Did you debug and see on which particular line does your application fail ?

      N 1 Reply Last reply
      0
      • N Neeraj Kr

        Hi I am a beginner in the .Net 3.5. I am making a XBAP application and trying to declare the connection string in the app.config file. When i am using the same in my code I am receiving an unexpected error: Cannot create instance of 'Page1' defined in assembly 'WpfBrowserApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Page1.xaml' Line 1 Position 7. I am using the following in the code behind:

        string conn = ConfigurationSettings.AppSettings["ConnectionString"].ToString();
        DataSet dsEmployees = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "sp_fetchEmployees");
        lstEmployees.DataContext = dsEmployees;

        Kindly help as I am stuck completely

        -----Have A Nice Day-----

        modified on Friday, March 13, 2009 11:16 AM

        E Offline
        E Offline
        Eslam Afifi
        wrote on last edited by
        #3

        I'm not expert in this. XBAP run in partial-trust. You should expose your database through a web service (ASP.NET, WCF, ...). You may want to take a look at ADO.NET Data Services. Or include the SqlClientPermission (or OleDp's) but in this case the application can fail to run because this elevated permission.

        Eslam Afifi

        N 1 Reply Last reply
        0
        • E Eslam Afifi

          I'm not expert in this. XBAP run in partial-trust. You should expose your database through a web service (ASP.NET, WCF, ...). You may want to take a look at ADO.NET Data Services. Or include the SqlClientPermission (or OleDp's) but in this case the application can fail to run because this elevated permission.

          Eslam Afifi

          N Offline
          N Offline
          Neeraj Kr
          wrote on last edited by
          #4

          Yes you are true. I will have to use a web service to expose the data to the web application, XBAP from the SQL Server. But, I don't understand what was the need of this. Why was this not considered in the 2005 or earlier edition?

          -----Have A Nice Day-----

          E 1 Reply Last reply
          0
          • A ABitSmart

            ConfigurationSettings.AppSettings is now obsolete. See here MSDN[^]. Instead use ConfigurationManager[^]/WebConfigurationManager as recommended. Did you debug and see on which particular line does your application fail ?

            N Offline
            N Offline
            Neeraj Kr
            wrote on last edited by
            #5

            I am not able to use ConfigurationManager. When I type Configuration, the automatic help only shows ConfigurationSettings.

            -----Have A Nice Day-----

            A 1 Reply Last reply
            0
            • N Neeraj Kr

              I am not able to use ConfigurationManager. When I type Configuration, the automatic help only shows ConfigurationSettings.

              -----Have A Nice Day-----

              A Offline
              A Offline
              ABitSmart
              wrote on last edited by
              #6

              I shared you a link from MSDN which has example of it's usage - again link[^]

              N 1 Reply Last reply
              0
              • A ABitSmart

                I shared you a link from MSDN which has example of it's usage - again link[^]

                N Offline
                N Offline
                Neeraj Kr
                wrote on last edited by
                #7

                I wonder why I am not able to use ConfigurationManager instead of ConfigurationSettings, although I have used the Configuration class

                -----Have A Nice Day-----

                1 Reply Last reply
                0
                • N Neeraj Kr

                  Yes you are true. I will have to use a web service to expose the data to the web application, XBAP from the SQL Server. But, I don't understand what was the need of this. Why was this not considered in the 2005 or earlier edition?

                  -----Have A Nice Day-----

                  E Offline
                  E Offline
                  Eslam Afifi
                  wrote on last edited by
                  #8

                  From the MSDN[^]

                  In general, Internet applications should be restricted from having direct access to critical system resources, to prevent malicious damage.

                  As a said before, I'm not an expert but here is what i think it might be correct. Since XBAP are client side, I think they'd use the ODBC drivers at the client. But I'm not sure why they are considered a security risk (maybe because they're unmanaged code). I wish someone explain more or correct me if I'm wrong.

                  Eslam Afifi

                  N 1 Reply Last reply
                  0
                  • E Eslam Afifi

                    From the MSDN[^]

                    In general, Internet applications should be restricted from having direct access to critical system resources, to prevent malicious damage.

                    As a said before, I'm not an expert but here is what i think it might be correct. Since XBAP are client side, I think they'd use the ODBC drivers at the client. But I'm not sure why they are considered a security risk (maybe because they're unmanaged code). I wish someone explain more or correct me if I'm wrong.

                    Eslam Afifi

                    N Offline
                    N Offline
                    Neeraj Kr
                    wrote on last edited by
                    #9

                    I think you are right. They are client side application and do not even require a web server. This is the reason that they require a intermediate web service to provide the data from the database.

                    -----Have A Nice Day-----

                    E 1 Reply Last reply
                    0
                    • N Neeraj Kr

                      I think you are right. They are client side application and do not even require a web server. This is the reason that they require a intermediate web service to provide the data from the database.

                      -----Have A Nice Day-----

                      E Offline
                      E Offline
                      Eslam Afifi
                      wrote on last edited by
                      #10

                      I wonder why data access is a security risk that they are not allowed in partial-trust.

                      Eslam Afifi

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups