Connecting to SQL Server database in XBAP application [modified]
-
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
-
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
-
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
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
-
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
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-----
-
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 ?
-
I am not able to use ConfigurationManager. When I type Configuration, the automatic help only shows ConfigurationSettings.
-----Have A Nice Day-----
-
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-----
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
-
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
-
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-----
I wonder why data access is a security risk that they are not allowed in partial-trust.
Eslam Afifi