我无法在下面的代码中找到错误。当我使用SQLDataSource连接我的数据库时,没有错误。但是,如果我尝试写入自定义代码中使用相同的连接字符串的SqlDataSource用于连接数据库时,我遇到这样的错误:无法通过自定义代码使用相同的连接字符串连接到数据库sqldatasource使用
(provider:命名管道提供程序,error:40 - 无法打开到SQL Server的连接)
我猜想在我的代码中没有错误,但是在SQL 2008 Express的配置设置中。
在此先感谢...
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = "Data Source=ERHANEMREEROGLU/SQLEXPRESS;Initial Catalog=KET;Integrated Security=True";
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection=sqlcon;
sqlcmd.CommandText = "SELECT * FROM Login";
sqlcmd.CommandType = CommandType.Text;
sqlcmd.ExecuteNonQuery();
sqlcon.Close();
参考这篇文章。 http://stackoverflow.com/questions/11350983/unable-to-connect-to-sql-server-2008-in-net – 2012-07-06 09:25:51