Note that there are some explanatory texts on larger screens.

plurals
  1. POConnect to SQL Server 2012 Database with C# (Visual Studio 2012)
    primarykey
    data
    text
    <p>Evening all,</p> <p>I'm trying to connect to a SQL Server 2012 database from C#. My connection settings when using SQL Server Management Studio are as below:-</p> <pre><code>Server Type: Database Engine Server Name: Paul-PC\SQLEXPRESS Authentication: Windows Authentication Username: Greyed out Password: Greyed out </code></pre> <p>The name of the database I'm trying to connect to is "testDB".</p> <p>Here's my code:</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; namespace DatabaseConnection { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnConnect_Click(object sender, EventArgs e) { SqlConnection myConnection = new SqlConnection("server=localhost;" + "Trusted_Connection=yes;" + "database=testDB; " + "connection timeout=30"); try { myConnection.Open(); MessageBox.Show("Well done!"); } catch(SqlException ex) { MessageBox.Show("You failed!" + ex.Message); } } } } </code></pre> <p>Unfortunately, my code fails to connect with the following error:-</p> <p>"You failed!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."</p> <p>Any suggestions? SQL Server is running locally.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload