پیغام خطای A network-related or instance-specific error occurred
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: 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)
کد ام هم برنامه زیره:
SqlConnection objConnection = new SqlConnection("server=localhost;database=Pr;" +
"user id = sa;password= 123");
SqlDataAdapter objDataAdapter = new SqlDataAdapter();
DataSet objDataSet = new DataSet();
objDataAdapter.SelectCommand = new SqlCommand();
objDataAdapter.SelectCommand.Connection = objConnection;
objDataAdapter.SelectCommand.CommandText = "SELECT ProductName" +
"FROM Products";
objDataAdapter.SelectCommand.CommandType = CommandType.Text;
objConnection.Open();
objDataAdapter.Fill(objDataSet, "Products");
objConnection.Close();
grdProducts.AutoGenerateColumns = true;
grdProducts.DataSource = objDataSet;
grdProducts.DataMember = "Products";
objDataAdapter = null;
objConnection = null;
نقل قول: این پیغام خطا مال چیه؟
مشکل شما به خاطر کانکشن استرینگتون هست . به نظرم اونو به این صورت تغییر بده :
server = . ; database = pr ; integrated security=True
اینو تست کن خطا داشتی با متن خطا دوباره بفرست
نقل قول: این پیغام خطا مال چیه؟
نقل قول: این پیغام خطا مال چیه؟
دوست گل من پیغام خودش داره میگه !!! An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
شما از قسمت Reference این دو گزینه رو : System.Data.SqlClient.SqlException و System.Data.dll رو وارد پروژتون کنید مشکل حل خواهد شد :)