locked
The underlying connection was closed: The connection was closed unexpectedly. !!! RRS feed

  • Question

  • I have found a demo project "build an n-tier application with wcf" at :http://blogs.microsoft.co.il/blogs/bursteg/archive/2008/02/10/how-to-build-an-n-tier-application-with-wcf-and-datasets-in-visual-studio-2008.aspx?CommentPosted=true#commentmessage

    and then I create a new operation but it does not work...

    in Bursteg.Samples.DataAccess I create new classes "DBConnection.cs" and "AccountDAL.cs" this code :
    DBConnection.cs :

    public static SqlConnection Conn;
            public DBConnection()
            {
                try
                {
                    string strCon = "server=localhost\\SQLEXPRESS; Initial Catalog= Blog; Integrated security = True";
                    Conn = new SqlConnection(strCon);
                    Conn.Open();
                }
                catch (System.Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    Conn.Close();
                }
            }

    AccountDAL.cs :
       public DataTable GetAllAccount()
            {
                string strselect = "select * from Blogs";
                SqlDataAdapter daAccount = new SqlDataAdapter(strselect, DBConnection.Conn);
                DataTable dtAccount = new DataTable();
                daAccount.Fill(dtAccount);
                return dtAccount;
            }
    in Bursteg.Samples.Services.Contracts in definde new operation :
     [OperationContract]
        System.Data.DataTable GetAllAccount();
    and implement service operations :

     public DataTable GetAllAccount()
        {
            DataTable dtAccount = new DataTable();
            AccountDAL accountdal = new AccountDAL();
            dtAccount = accountdal.GetAllAccount();
            return dtAccount;
        }
    in Bursteg.Samples.Client I create new datagridview

     private void button1_Click(object sender, EventArgs e)
            {
                BlogServiceClient proxy = new BlogServiceClient();
                DataTable dtAccount = new DataTable();
                dtAccount = proxy.GetAllAccount();
                dataGridView1.DataSource = dtAccount;
            }
    I am greeting a error : "The underlying connection was closed: The connection was closed unexpectedly."
    I try to config file app.config at : closeTimeout,opentimeout, receivetimeout... and enable tracing at the server .. but it does not work. please help me ! this is my source code :
    link : http://cid-2911c9b1d5d570fe.skydrive.live.com/self.aspx/.Public/Bursteg.Samples.VS2008Datasets.rar

    Wednesday, May 5, 2010 4:00 AM

Answers

All replies

  • Hi,

    I could not able see project.

    At which point you are gettting this error? Client or server side, or while accessing db?

    Just check this one this might be helpful

    http://stackoverflow.com/questions/285345/the-underlying-connection-was-closed-the-connection-was-closed-unexpectedly

     


    Regards, Nakul
    • Marked as answer by Strongangel Wednesday, May 5, 2010 5:11 PM
    Wednesday, May 5, 2010 4:10 AM
  • this is my project :  http://www.mediafire.com/?zjxdimdjcz4 . I see that error on client. Exactly while accessing db !. Thanks.
    • Marked as answer by Strongangel Wednesday, May 5, 2010 5:10 PM
    • Unmarked as answer by Strongangel Wednesday, May 5, 2010 5:10 PM
    Wednesday, May 5, 2010 7:22 AM
  • Hi,

    Can you please do wcf tracing and get the actuall error message. To run wcf tracing you can check the following article.

    http://msdn.microsoft.com/en-us/library/ms730064.aspx

    Once you enable logging you can get the error message and once you get it please post it here.


    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
    • Marked as answer by Strongangel Wednesday, May 5, 2010 5:10 PM
    Wednesday, May 5, 2010 8:01 AM
  • I try adding to do wcf tracing as you say. and this is stack trace


    Server stack trace:
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Bursteg.Samples.Client.Proxy.IBlogService.GetAllAccount()
       at Bursteg.Samples.Client.Proxy.BlogServiceClient.GetAllAccount() in c:\users\tranngochau\desktop\bursteg.samples.vs2008datasets\bursteg.samples.vs2008datasets\bursteg.samples.client\service references\proxy\reference.cs:line 64
       at Bursteg.Samples.Client.ClientApplication.button1_Click(Object sender, EventArgs e) in C:\Users\TranNgocHau\Desktop\Bursteg.Samples.VS2008Datasets\Bursteg.Samples.VS2008Datasets\Bursteg.Samples.Client\ClientApplication.cs:line 39
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Bursteg.Samples.Client.Program.Main() in C:\Users\TranNgocHau\Desktop\Bursteg.Samples.VS2008Datasets\Bursteg.Samples.VS2008Datasets\Bursteg.Samples.Client\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

     

    thanks Haripraghash .

    Wednesday, May 5, 2010 4:20 PM