ERUM
Apr 14th, 2010, 04:23 AM
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 is <connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=(IRAM-PC);Database=Northwind;User Id=sa;Password=sa" providerName="System.Data.SqlClient" />
</connectionStrings>
other piece of code is hereusing 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]
}
}
giving me an exception on the line conn.Open();
any help!!
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 is <connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=(IRAM-PC);Database=Northwind;User Id=sa;Password=sa" providerName="System.Data.SqlClient" />
</connectionStrings>
other piece of code is hereusing 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]
}
}
giving me an exception on the line conn.Open();
any help!!