C#(Visual Studio 2012)을 사용하여 SQL Server 2012 데이터베이스에 연결

안녕하세요,

C#에서 SQL Server 2012 데이터베이스에 연결하려고 합니다. SQL Server 관리 스튜디오를 사용할 때 내 연결 설정은 다음과 같습니다.

Server Type:    Database Engine
Server Name:    Paul-PC\SQLEXPRESS
Authentication: Windows Authentication
Username:   Greyed out
Password:   Greyed out 

연결하려는 데이터베이스의 이름은 "testDB" 입니다.

다음은 제 코드입니다:

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);
            }

        }
    }
}

안타깝게도 내 코드가 다음 오류와 함께 연결에 실패합니다.

실패했습니다!"SQL Server에 연결하는 동안 네트워크 관련 또는 인스턴스 관련 오류가 발생했습니다. 서버를 찾을 수 없거나 액세스할 수 없습니다. 인스턴스 이름이 올바른지, SQL Server가 원격 연결을 허용하도록 구성되어 있는지 확인하세요;

제안 사항이 있나요? SQL Server가 로컬에서 실행 중입니다.

연결 문자열에서 서버=로컬호스트서버 = Paul-PC\\SQLEXPRESS;로 바꿉니다;

해설 (0)

서버=로컬호스트서버=.\SQLEXPRESS`로 바꾸면 문제가 해결될 수 있습니다.

해설 (2)

시도해 보세요:

SqlConnection myConnection = new SqlConnection("Database=testDB;Server=Paul-PC\\SQLEXPRESS;Integrated Security=True;connect timeout = 30");
해설 (0)