I am doing some tests in using LINQ to SQL class in Visual web part.
I am unsuccessful due to some unknown steps missed and confusion on authentication.
Environment Scenario:
Northwind database with a SQL service account.
SQL server enabled with windows and SQL authentication.
Development Method Tried:
1. Created a 'Class Library' project with 'Linq to SQL added'
2. Added SQL connection with 'sql user name and password'. The app.config file as shown below.
<connectionStrings><add name="AdventureEntityClass.Properties.Settings.NorthwindConnectionString" connectionString="Data Source=myserver;Initial Catalog=Northwind;User Id=spsqlservice;Password=sqlpwd" providerName="System.Data.SqlClient" /></connectionStrings>
3. Compiled project. Created new project sharepoint visual web part
4. Added the above 'linq to sql' dll as a reference .
5. Added a feature activation/deactivation method to modify 'web.conifg' file with connection string.
6. Wrote below code ( as i thought straight forward) in webpart control file.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Web.UI.WebControls.WebParts; using AdventureEntityClass; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EntityVisualWebPart.VisualWebPart1 { [ToolboxItemAttribute(false)] public partial class VisualWebPart1 : WebPart { protected void Page_Load(object sender, EventArgs e) { AdventureClassDataContext adventureclass = new AdventureClassDataContext(); var allemployees = (from employe in adventureclass.Employees where employe.FirstName != null select employe).ToList(); GridView1.DataSource = allemployees; GridView1.DataBind(); } } }
Though the code complied. But my grid view in webpart with no result and error.
My question :
1. what steps am I missing?
2. How to make sure the context class getting connection string from web.config file?
3. Do I need to create again entity frame work on top of LINQ to SQL as explained in below link.
4. Can't I escape BDC entity model and BCS service application?
5. how to compile the connection string in LINQ to SQL if I use 'Secure Store service' for production environment.?
6. Does I need to implement impersonation method?
In simple. I want to create a server side farm solution using 'LINQ to SQL ' class without BCS service to do CRUD operations on SQL database using Visual Webpart?.
I want to achieve many to many relation ship and to use stored procedures and join mutliple SQL tables.
Please give with example code.
Murali Krishna Dittakavi *********************** If my answer/post resolved your query could you mark the post as answered. If it is helpful then vote as Helpful. Thanks