Click here to Skip to main content
15,922,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
First time i launch my website i get this error
C#
System.ComponentModel.Win32Exception network path was not found


but when i refresh my site there is no problem.

I am using and db data access file written in C#, when i debug it shows there error is in line 22. But i dont understand why, because i am opening and closing everytime.

my dbdataAccess file

C#
public class dbDataAccess
{
    readonly string _strDB = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;

    public DataTable GetData(SqlCommand cmd)
    {
       
        DataSet objDS = new DataSet();
        SqlConnection objConnect = new SqlConnection(_strDB);

            cmd.Connection = objConnect;
            SqlDataAdapter objDa = new SqlDataAdapter();
            objDa.SelectCommand = cmd;
            objDa.Fill(objDS);//this is where it fails

      
            objConnect.Close();
        

        return objDS.Tables[0];
    }   

    public void ModifyData(SqlCommand cmd)
    {
        
        SqlConnection objConnect = new SqlConnection(_strDB);

        cmd.Connection = objConnect;
        objConnect.Open();
        cmd.ExecuteNonQuery();
        objConnect.Close();
    }

    public int intModifyData(SqlCommand CMD)
    {
        SqlConnection objConn = new SqlConnection(_strDB);
        int antalrk;
        try
        {
            CMD.Connection = objConn;
            objConn.Open();
            antalrk = CMD.ExecuteNonQuery();
        }
        catch
        {
            throw;

        }

        finally
        {
            objConn.Close();
        }

        return antalrk;
    }





}


And my connection string in web config
XML
<add name="connect" connectionString="Data Source=**********;Initial Catalog=********;User ID=********;Password=********" providerName="System.Data.SqlClient"/>


and the first method i call.
C#
public DataTable GetAll()
   {
       string strSQL = "********";
       SqlCommand CMD = new SqlCommand(strSQL);
       return objCMD.GetData(CMD);

   }


What I have tried:

debugging and search in google and tryede different solutions and connection strings
Posted
Updated 2-Nov-16 2:26am
v2
Comments
ZurdoDev 1-Nov-16 7:02am    
Which line is line 22 and what is the exact error?

1 solution

There may be some reasons :
1) SQL Server in services is not running.
2) Distributed Transaction Coordinator service is not running.
Please check these two services and check connection string also.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900