I m using win7 and VS2008 and sql server 2005
I have an application of silver light with WCF ,(i need to bind grid with database records) but its giving me an excpetion while opening conenction to database..Although i make changes in sql server Express to connect locally and remotely (asi m using WFCF). my connection string in web.config isother piece of code is hereCode:<connectionStrings> <add name="NorthwindConnectionString" connectionString="Data Source=(IRAM-PC);Database=Northwind;User Id=sa;Password=sa" providerName="System.Data.SqlClient" /> </connectionStrings>giving me an exception on the line conn.Open();Code:using System.Data; using System.Data.SqlClient; using System; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Activation; using System.Collections.Generic; using System.Text; namespace SilverlightWithWCFService.Web { [ServiceContract(Namespace = "")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class SampleService { [OperationContract] public List<Customer> CustomerList() { string nwConn = System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString; var custList = new List<Customer>(); using (SqlConnection conn = new SqlConnection(nwConn)) { const string sql = "SELECT TOP 10 CustomerID, CompanyName, ContactName FROM Customers"; conn.Close(); conn.Open(); using (SqlCommand cmd = new SqlCommand(sql, conn)) { SqlDataReader dr = cmd.ExecuteReader( CommandBehavior.CloseConnection); if (dr != null) while (dr.Read()) { var cust = new Customer { CustomerName = dr.GetString(0), CompanyName = dr.GetString(1), ContactName = dr.GetString(2) }; custList.Add(cust); } return custList; } } } // Add more operations here and mark them with [OperationContract] } }
any help!!




Reply With Quote