<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SQL Database Integration</title><link>https://www.infopathdev.com:443/forums/47.aspx</link><description>For questions concerning issues in the integration of SQL and Microsoft InfoPath.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: SQL Connection Error</title><link>https://www.infopathdev.com:443/forums/thread/17328.aspx</link><pubDate>Fri, 30 Jun 2006 17:49:27 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:17328</guid><dc:creator>Greg Collins</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/17328.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=47&amp;PostID=17328</wfw:commentRss><description>The first line gives away the issue: System.Security.SecurityException&lt;br /&gt;&lt;br /&gt;Sounds like your form is going to need to be full trust for your code to work as it is written</description></item><item><title>SQL Connection Error</title><link>https://www.infopathdev.com:443/forums/thread/16825.aspx</link><pubDate>Wed, 28 Jun 2006 18:58:38 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:16825</guid><dc:creator>epora</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/16825.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=47&amp;PostID=16825</wfw:commentRss><description>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:&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;System.Security.SecurityException was unhandled by user code&lt;br /&gt;  Message="Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."&lt;br /&gt;  Source="mscorlib"&lt;br /&gt;  StackTrace:&lt;br /&gt;       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark&amp; stackMark, Boolean isPermSet)&lt;br /&gt;       at System.Security.PermissionSet.Demand()&lt;br /&gt;       at System.Data.Common.DbConnectionOptions.DemandPermission()&lt;br /&gt;       at System.Data.SqlClient.SqlConnection.PermissionDemand()&lt;br /&gt;       at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)&lt;br /&gt;       at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)&lt;br /&gt;       at System.Data.SqlClient.SqlConnection.Open()&lt;br /&gt;       at AICPA.InfoPath.FormCode.GetNextMasterCode()&lt;br /&gt;       at AICPA.InfoPath.FormCode.SetMasterCode()&lt;br /&gt;       at AICPA.InfoPath.FormCode.FormEvents_Loading(Object sender, LoadingEventArgs e)&lt;br /&gt;       at Microsoft.Office.InfoPath.Internal.FormEventsHost.OnLoad(DocReturnEvent pEvent)&lt;br /&gt;       at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;This code is running on my local development machine, which fully trusts assemblies by default.&lt;br /&gt;&lt;br /&gt;Here's the function that's causing a problem:&lt;br /&gt;-------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;  private string GetNextMasterCode()&lt;br /&gt;      {&lt;br /&gt;         System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection("Data Source=SERVER;Initial Catalog=DATABASE;User Id=user;Password=password;");&lt;br /&gt;   &lt;br /&gt;         System.Data.SqlClient.SqlCommand sqlCommand;&lt;br /&gt;         string sql = "";&lt;br /&gt;         object currentMasterCode;&lt;br /&gt;&lt;br /&gt;         sql = "SELECT MAX(mastercode) FROM MasterCodeDistribution";&lt;br /&gt;         sqlCommand = new System.Data.SqlClient.SqlCommand(sql, sqlConnection);&lt;br /&gt;        &lt;br /&gt;         sqlConnection.Open();&lt;br /&gt;         currentMasterCode = (string)sqlCommand.ExecuteScalar();&lt;br /&gt;         sqlConnection.Close();&lt;br /&gt;&lt;br /&gt;         return currentMasterCode;&lt;br /&gt;      }&lt;br /&gt;----------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;I have tried both sql account authentication and trusted (domain admin).&lt;br /&gt;&lt;br /&gt;Has anyone run into this?</description></item></channel></rss>