Click here to Skip to main content
14,643,165 members
Rate this:
Please Sign up or sign in to vote.
See more:
<configuration>
  <!--<configSections>
  </configSections>-->
  <connectionStrings>
    <add name="ConnectionName" providerName="System.Data.SqlClient" connectionString="Data Source=MyServerName;Initial Catalog=MyDatabaceName;Integrated Security=True"  />
  </connectionStrings>
</configuration>


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


and a function to open connection:
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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" />
   
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");
Rate this:
Please Sign up or sign in to vote.

Solution 2

change the server name


<add name="conn" connectionstring="Server=MyServerName;Database=myDataBase;Integrated Security=true;" providername="System.Data.SqlClient"/>
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100