accessing sql server in C# code on form load - InfoPath Dev
in

InfoPath Dev

accessing sql server in C# code on form load

Last post 07-16-2012 01:19 AM by rajkumar.bathula. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-08-2012 10:45 AM

    accessing sql server in C# code on form load

    Hi, I am unable to connect to MS SQL server database in form load code in C#. I am using infopath 2010. It gives permission exception(Detailed exception given below).

    Please help me out in geting rid of this issue.

    Below is code i am using in my Form load:

    using (SqlConnection conn = new SqlConnection("Data Source=systemName\\servername;Initial Catalog=SharePoint_DB;User ID=admin;Password=Pass01*;Integrated Security=true;"))

    {

    conn.Open();

    emailAlias.SetValue(
    "xyz");

    conn.Close();

    }

     

    Exception at connection Open() statement :

    [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."}

    thanks beforehand

    raj

    Thank you
    Raj
  • 07-04-2012 07:16 AM In reply to

    Re: accessing sql server in C# code on form load

    Hi raj,

    I am facing the same situation, have you solve it?

  • 07-04-2012 07:45 AM In reply to

    Re: accessing sql server in C# code on form load

    As far as I know, the only way to use code like the above to access a database is for your form to be full trust.

    Instead, you should set up a data connection to the SQL server, and if necessary, manipulate that from code.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-16-2012 01:19 AM In reply to

    Re: accessing sql server in C# code on form load

    Hi

     

    as Jimmy said, give full trust by navigating to Form options-->Security--> and select full trust.

     

     

    Thank you
    Raj
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.