I'm not exactly sure why this error was occurring I was assuming it was because of my App.Config
configuration manager connection string I've tried dabbling with it but nothing seems to work.
Error
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: 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)
My app.config
:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="fluxConnection"
connectionString="Data Source=.;Initial Catalog=database; Integrated Security=SSPI;User ID=root;Password=;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Code:
private void metroButton2_Click(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["fluxConnection"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
con.Open();
if (con.State == ConnectionState.Open) {
MessageBox.Show("Connection Successful");
}
if (con.State == ConnectionState.Closed)
{
MessageBox.Show("Connection is Closed");
}
if (con.State == ConnectionState.Broken)
{
MessageBox.Show("Connection is Broken");
}
con.Close();
}