shd.online
سه شنبه 12 تیر 1397, 10:20 صبح
سلام
کدم اینه
public void SqlConnection()
{
// 1. Instantiate the connection
SqlConnection conn = new SqlConnection("Data Source=SHD2/SHD_INSTANCE;Initial Catalog=davarpanah_db;Integrated Security=True");
SqlDataReader rdr = null;
try
{
// 2. Open the connection
conn.Open();
// 3. Pass the connection to a command object
SqlCommand cmd = new SqlCommand("select * from CSDic", conn);
// 4. Use the connection
// get query results
rdr = cmd.ExecuteReader();
// print the CustomerID of each record
while (rdr.Read())
{
richTextBox1.Text = "1";
}
}
finally
{
// close the reader
if (rdr != null)
{
rdr.Close();
}
// 5. Close the connection
if (conn != null)
{
conn.Close();
}
}
}
نام سرور همینه فقط بک اسلش رو کردم اسلش تا خطا نگیره ولی روی open کردن خطا میده:
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)
کدم اینه
public void SqlConnection()
{
// 1. Instantiate the connection
SqlConnection conn = new SqlConnection("Data Source=SHD2/SHD_INSTANCE;Initial Catalog=davarpanah_db;Integrated Security=True");
SqlDataReader rdr = null;
try
{
// 2. Open the connection
conn.Open();
// 3. Pass the connection to a command object
SqlCommand cmd = new SqlCommand("select * from CSDic", conn);
// 4. Use the connection
// get query results
rdr = cmd.ExecuteReader();
// print the CustomerID of each record
while (rdr.Read())
{
richTextBox1.Text = "1";
}
}
finally
{
// close the reader
if (rdr != null)
{
rdr.Close();
}
// 5. Close the connection
if (conn != null)
{
conn.Close();
}
}
}
نام سرور همینه فقط بک اسلش رو کردم اسلش تا خطا نگیره ولی روی open کردن خطا میده:
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)