I am attempting to connect to a SQL Server 2014. A week or so ago it seemed to work, now it does not. The systems team did upgrade recently to 2014. What's weird is that I'm able to use SQL Server Management Studio to connect, ODBC, and telnet. It's just an issue with C#. Additionally, this exact program runs on another server as compiled/release. It's just not running on my system using debug (or fully compiled/release).
I checked through the documentation -- disabled all the firewalls, had STP check the server... nada
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 C# code:
namespace SQLTest
{
class Program
{
static void Main(string[] args)
{
string connectionString = ConfigurationManager.ConnectionStrings["SQLConn"].ConnectionString;
string OrganizationSqlStr = @"SELECT * FROM school";
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(OrganizationSqlStr, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.Write(reader["School_ID"] + " | ");
Console.Write(reader["title"] + "\n\r");
}
Console.ReadKey();
}
}
}
app.config
:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings>
<add name="SQLConn"
connectionString="server=SERVER;database=DATABASE;uid=USERNAME;password=PASSWORD"/>
</connectionStrings>
</configuration>