Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error:
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)

C#
namespace ExportDataTableApplication
{
    class ExportDataTable
    {
        DateTime datetime = DateTime.Now;

        static void Main(string[] args) 
        {
            Console.WriteLine("Running App");

            DataSet ds = new DataSet();
            DateTime datetime = DateTime.Now;
            bool exception= false;

            string connString = string.Format("data source={0}; initial catalog={1}; Integrated Security ={2}; Connection Timeout={3}",
                       ConfigurationManager.AppSettings["DataSource"],
                       ConfigurationManager.AppSettings["InitialCatalog"],
                       ConfigurationManager.AppSettings["IntegratedSecurity"],
                       ConfigurationManager.AppSettings["TimeOut"]);

            using (SqlConnection conn = new SqlConnection(connString))
            {

                try //Call stored procedure
                {

                    SqlCommand sqlComm = new SqlCommand("dbo.Test", conn);

                    sqlComm.CommandType = CommandType.StoredProcedure;

                    SqlDataAdapter da = new SqlDataAdapter(sqlComm);

                    da.Fill(ds);
                }
Posted

the network connection could not found in your connection...


Initial Catalog ="in your database connection name like db name "


string connString = string.Format("data source={0}; initial catalog={1}; Integrated Security ={2}; Connection Timeout={3}",





it may help you..
 
Share this answer
 
v2
Comments
Member 11878313 5-Aug-15 2:49am    
I did at in Initial Catalog "..." in my apps config. So what do you mean by ur codes?

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