I'm currently trying to connect from Visual Studio 2013 C# application to a SQL Server 2012 instance but I'm running into troubles. Namely error 26 that no connection could be created.
My question there is what could still be wrong with what I'm doing (I'll post the code snippets I use below and then also what I controlled so far / steps I took):
Code
I created an application config which has the following line:
<connectionStrings>
<add name="DefaultConnectionString"
connectionString="Data Source=TH-HP\SQLEXPRESS;Initial Catalog=BB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False"
providerName="System.Data.SqlClient"/>
</connectionStrings>
I use an intermediary class I call Database
to create the connection strings and run the commands.
When initializing it I use the following command (which sets the private variable connectionStr
):
Database db = new Database(Properties.Settings.Default.ConnectionString);
Then when I try to open the connection:
SqlConnection con = new SqlConnection(this.connectionStr);
con.Open();
The error happens.
Steps
(as note both the program and the SQL Server instance are running on the same machine)
- Correct servername
- Correct catalogue name
- SQL Server accepts remote connections
- Server Browser is running
- Server itself is running (connected to it via management console)
Like I said I'm running out of ideas what to check next.