Problem calling stored procedure from InfoPath web browser version

  • 28 August 2008
  • 2 replies
  • 4 views

Badge +1

I have InfoPath (web browser version) to start a K2 workflow under MOSS 2007 environment. In this InfoPath form, there is .NET code behind it (in InfoPath via Tools -> Programming -> Microsoft Visual Studio Tools for Applications.

In that .NET code, I put a section to call a stored procedure, however I got below error:

 Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.


I know I can use SmartObjects to call a stored procedure but for a simple routine like this I prefer to do it in the code behind InfoPath form. What am I missing.

Below is my code:

         public void CTRL4_5_Clicked(object sender, ClickedEventArgs e)
        {
            // Write your code here.
            XPathNavigator navigator = this.MainDataSource.CreateNavigator();
            // Display Action Description based on Action Code entered
            string actionCode = navigator.SelectSingleNode("/my:myFields/my:ActionCode", NamespaceManager).Value;
            string connectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=XYZ;Data Source=BLACKPEARL";
            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "GetActionDesc";

            // stored procedure parameters
            cmd.Parameters.Add(new SqlParameter("@action_code", actionCode));

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);


            string actionDesc;

            if (ds.Tables[0].Rows.Count == 1)
            {
                actionDesc = ds.Tables[0].Rows[0].ItemArray[0].ToString();
                navigator.SelectSingleNode("/my:myFields/my:ActionDesc", NamespaceManager).SetValue(actionDesc);
            }

            
        }

 And below is the complete error message:

 Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.PermissionSet.Demand()
at System.Data.Common.DbConnectionOptions.DemandPermission()
at System.Data.SqlClient.SqlConnection.PermissionDemand()
at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at CodeBehindPart3.FormCode.CTRL4_5_Clicked(Object sender, ClickedEventArgs e)
at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.<>c__DisplayClass6.<>c__DisplayClass8.<add_Clicked>b__1()
at Microsoft.Office.InfoPath.Server.Util.DocumentReliability.InvokeBusinessLogic(Thunk thunk)
at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.<>c__DisplayClass6.<add_Clicked>b__0(Object sender, ClickedEventArgs e)
at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.FireClickedEvent(Object sender, ClickedEventArgs args)
at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonFormCode.<>c__DisplayClass2.<>c__DisplayClass5.<Click>b__1()
at Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.CallFormCodeWithExceptionHandling(UserMessages userMessages, OMCall d)
at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonFormCode.<>c__DisplayClass2.<Click>b__0()
at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonFormCode.Click(Document document, XPathNavigator container)
at Microsoft.Office.InfoPath.Server.DocumentLifetime.EventClick.Play(Document document, BindingServices bindingServices, EventLogProcessor eventLogProcessor)
at Microsoft.Office.InfoPath.Server.DocumentLifetime.Event.PlayEvent(Document document, BindingServices bindingServices, EventLogProcessor eventLogProcessor)
at Microsoft.Office.InfoPath.Server.DocumentLifetime.EventLogProcessor.<>c__DisplayClass1.<ExecuteLog>b__0()
at Microsoft.Office.InfoPath.Server.DocumentLifetime.EventLogProcessor.ExecuteLog(Int32 expectedEventLogID)
at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.<>c__DisplayClass6.<PlayEventLog>b__3()
at Microsoft.Office.Server.Diagnostics.FirstChanceHandler.ExceptionFilter(Boolean fRethrowException, TryBlock tryBlock, FilterBlock filter, CatchBlock catchBlock, FinallyBlock finallyBlock)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Data.SqlClient.SqlClientPermission
The first permission that failed was:
<IPermission class="System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
AllowBlankPassword="False">
<add ConnectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SCC;Data Source=BLACKPEARL"
KeyRestrictions=""
KeyRestrictionBehavior="AllowOnly"/>
</IPermission>

The demand was for:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
AllowBlankPassword="False">
<add ConnectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SCC;Data Source=BLACKPEARL"
KeyRestrictions=""
KeyRestrictionBehavior="AllowOnly"/>
</IPermission>
</PermissionSet>

The granted set of the failing assembly was:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="Execution"/>
<IPermission class="System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100B9F84D4DB507056644142854AFF05D57276C7CEA5212078223727D1B5010BA6470BF67ECABA1B41D200E9B53E04CF5AE5D9EF6B7DB26218D9EFA989088125B30C2474676D16FD111396112477FD8730D4661DD312EEF57A00506AEE92CD1A7B8EF46F32FA7EC810DD4CD866B5ED62FAA97434488C0473435BC518D35B72E87B7"
Name="CodeBehindPart3"
AssemblyVersion="1.0.3162.17376"/>
<IPermission class="System.Security.Permissions.UrlIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Url="file:///C:/Inetpub/wwwroot/wss/VirtualDirectories/moss.denallix.com80/"/>
<IPermission class="System.Security.Permissions.ZoneIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Zone="MyComputer"/>
<IPermission class="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Level="Minimal"/>
<IPermission class="Microsoft.SharePoint.Security.WebPartPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
version="1"
Connections="True"/>
</PermissionSet>

The assembly or AppDomain that failed was:
CodeBehindPart3, Version=1.0.3162.17376, Culture=neutral, PublicKeyToken=2b29b8f6dd4bcbb6
The method that caused the failure was:
Void CTRL4_5_Clicked(System.Object, Microsoft.Office.InfoPath.ClickedEventArgs)
The Zone of the assembly that failed was:
MyComputer
The Url of the assembly that failed was:
file:///C:/Inetpub/wwwroot/wss/VirtualDirectories/moss.denallix.com80/
 
 
 
 
 
   

 


2 replies

Badge +11

InfoPath forms with code-behind need a code-signing certificate.  You might also have to increase the trust level of the form.

Badge +1
Thank you.

Reply