C#连接SQL server2008 出现错误
Anetwork-relatedorinstance-specificerroroccurredwhileestablishingaconnectiontoSQLServ...
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)
using System;
using System.Data.SqlClient;
public class a
{
public static void Main(string[] args)
{
string source = "server = (loacal);" +
"integrated security = SSPI;" +
"database = nihao";
string select = "update buhao" +
"set age = 10" +
"where name= 'zhang'";
SqlConnection conn = new SqlConnection(source);
conn.Open();
SqlCommand cmd = new SqlCommand(select, conn);
int rowsReturned = cmd.ExecuteNonQuery();
Console.WriteLine("{0} rows affect!");
conn.Close();
Console.WriteLine();
}
}
这是我编写的代码,刚刚才接触C#有关数据的操作 展开
using System;
using System.Data.SqlClient;
public class a
{
public static void Main(string[] args)
{
string source = "server = (loacal);" +
"integrated security = SSPI;" +
"database = nihao";
string select = "update buhao" +
"set age = 10" +
"where name= 'zhang'";
SqlConnection conn = new SqlConnection(source);
conn.Open();
SqlCommand cmd = new SqlCommand(select, conn);
int rowsReturned = cmd.ExecuteNonQuery();
Console.WriteLine("{0} rows affect!");
conn.Close();
Console.WriteLine();
}
}
这是我编写的代码,刚刚才接触C#有关数据的操作 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询