Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<configuration>
  <!--<configSections>
  </configSections>-->
  <connectionStrings>
    <add name="ConnectionName" providerName="System.Data.SqlClient" connectionString="Data Source=MyServerName;Initial Catalog=MyDatabaceName;Integrated Security=True"  />
  </connectionStrings>
</configuration>


C#
SqlConnection Sqlc = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionName"].ConnectionString);


and a function to open connection:
C#
OpenConnection(Sqlc);

public bool OpenConnection(SqlConnection con)
{
  if (Sqlc.State == System.Data.ConnectionState.Closed)
      Sqlc.Open();                                 //error is here:' Instance failure'
 return true;
}
Posted
Updated 15-Feb-14 20:32pm
v2

check whether space is there in between initial and catalog catalog

if still problem persists, use like following
<add name="conn" connectionstring="Server=.;Database=myDb;Trusted_Connection=True;" providername="System.Data.SqlClient" />
 
Share this answer
 
v3
Comments
mit62 16-Feb-14 2:41am    
well my databas is not on local server "Server=.".

plus,application run without error when I set this connection string inside my program.

public SqlConnection Sqlc = new SqlConnection("Data Source=MyServerName;
Initial Catalog=myDataBase;Integrated Security=True");
change the server name


<add name="conn" connectionstring="Server=MyServerName;Database=myDataBase;Integrated Security=true;" providername="System.Data.SqlClient"/>
 
Share this answer
 
v2
Comments
mit62 16-Feb-14 9:36am    
it doesn't work
Abhishek Kumar Goswami 16-Feb-14 9:38am    
can u share error msg
mit62 16-Feb-14 12:53pm    
A 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)
Abhishek Kumar Goswami 16-Feb-14 13:24pm    
check this thread i think this will surely help you

http://www.codeproject.com/Questions/335874/A-network-related-or-instance-specific-error-occur

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