SQL Connection Error - InfoPath Dev
in

InfoPath Dev

SQL Connection Error

Last post 06-30-2006 10:49 AM by Greg Collins. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-28-2006 11:58 AM

    • epora
    • Not Ranked
    • Joined on 06-20-2006
    • USA
    • Posts 5

    SQL Connection Error

    I have an InfoPath form that is bound to a schema. I am trying to implement some code in Visual Studio (C#) that will make a call to a database to initialize some fields on the form load. I have hit a wall though with the following exception:
    --------------------------------------------------------------------
    System.Security.SecurityException was unhandled by user code
    Message="Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
    Source="mscorlib"
    StackTrace:
    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 AICPA.InfoPath.FormCode.GetNextMasterCode()
    at AICPA.InfoPath.FormCode.SetMasterCode()
    at AICPA.InfoPath.FormCode.FormEvents_Loading(Object sender, LoadingEventArgs e)
    at Microsoft.Office.InfoPath.Internal.FormEventsHost.OnLoad(DocReturnEvent pEvent)
    at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)

    --------------------------------------------------------------------

    This code is running on my local development machine, which fully trusts assemblies by default.

    Here's the function that's causing a problem:
    -------------------------------------------------------------------

    private string GetNextMasterCode()
    {
    System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection("Data Source=SERVER;Initial Catalog=DATABASE;User Id=user;Password=password;");

    System.Data.SqlClient.SqlCommand sqlCommand;
    string sql = "";
    object currentMasterCode;

    sql = "SELECT MAX(mastercode) FROM MasterCodeDistribution";
    sqlCommand = new System.Data.SqlClient.SqlCommand(sql, sqlConnection);

    sqlConnection.Open();
    currentMasterCode = (string)sqlCommand.ExecuteScalar();
    sqlConnection.Close();

    return currentMasterCode;
    }
    ----------------------------------------------------------------------

    I have tried both sql account authentication and trusted (domain admin).

    Has anyone run into this?
  • 06-30-2006 10:49 AM In reply to

    The first line gives away the issue: System.Security.SecurityException

    Sounds like your form is going to need to be full trust for your code to work as it is written
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.