我在连接到Microsoft SQL Server 2012时遇到一些问题。这是我的代码:
private void conButton_Click(object sender, EventArgs e)
{
string conString;
SqlConnection appMessage;
conString = @"Data Source=DHRANTONIUSVICT\SQLA; Initial Catalog=AppMessage; User ID=myid; Password=mypass; Server=localhost\sqlexpress";
appMessage = new SqlConnection(conString);
try
{
appMessage.Open();
MessageBox.Show("Connection is stable. Starting up the engines...");
}
catch (Exception)
{
MessageBox.Show("Connection to HQ is unstable. Need engineers ASAP!");
}
不知怎的,我无法连接到我的SQL Server。 我做错了什么?
请记住,我不熟悉这个SQL的东西。
答案 0 :(得分:6)
使用DataSource或Server.You同时使用
conString = @"Data Source=DHRANTONIUSVICT\SQLA; Initial Catalog=AppMessage; User ID=myid; Password=mypass ";
请参阅SqlConnection.ConnectionString documentation: