Results 1 to 6 of 6

Thread: [RESOLVED] SilverLigh with WCF throwing an exception while connecting database

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Resolved [RESOLVED] SilverLigh with WCF throwing an exception while connecting database

    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
    Code:
    	<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 here
    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]
        }
    }
    giving me an exception on the line conn.Open();

    any help!!
    There is no achievement without goals

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: SilverLigh with WCF throwing an exception while connecting database

    sorry i forgot to to mention the exception in my last post
    Code:
     network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
    There is no achievement without goals

  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: SilverLigh with WCF throwing an exception while connecting database

    That exception just simply means that it cannot connect to the SQL database using that connection string. Are you sure the connection string is correct? Can you confirm that the SQL database is actually accessible with that username and password remotely - you could try using SQL Management Studio to connect from whichever machine you are testing the silverlight app from and seeing if you can connect into the remote SQL database from there.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: SilverLigh with WCF throwing an exception while connecting database

    in fact user name and password is correct.and i m doing that application locally at my machine.but still I would check what are other possibilites
    There is no achievement without goals

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: SilverLigh with WCF throwing an exception while connecting database

    Ok ,ResolveD, just barckets was creating problem in webconfig
    There is no achievement without goals

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [RESOLVED] SilverLigh with WCF throwing an exception while connecting database

    ahh, glad you got it fixed
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width