public void GridviewCopyTable()
{
SqlConnection connectionSource = new SqlConnection(connStringSource);
SqlConnection connectionDest = new SqlConnection(connStringDest);
DataSet dataSetSource = new DataSet();
DataSet dataSetDest = new DataSet();
try
{
connectionSource.Open(); string selectedString = "SELECT * FROM [dbo].[Demo]";
SqlCommand command = new SqlCommand(selectedString, connectionSource);
SqlDataAdapter dataAdapter= new SqlDataAdapter(command);
dataAdapter.SelectCommand = command;
dataAdapter.Fill(dataSetSource);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
connectionSource.Close();
}
try
{
connectionDest.Open();
dataSetDest = dataSetSource.Copy();
gridViewCopy.DataSource = dataSetDest;
gridViewCopy.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
connectionDest.Close();
}
}
异常: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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 提前膜拜大侠~
{
SqlConnection connectionSource = new SqlConnection(connStringSource);
SqlConnection connectionDest = new SqlConnection(connStringDest);
DataSet dataSetSource = new DataSet();
DataSet dataSetDest = new DataSet();
try
{
connectionSource.Open(); string selectedString = "SELECT * FROM [dbo].[Demo]";
SqlCommand command = new SqlCommand(selectedString, connectionSource);
SqlDataAdapter dataAdapter= new SqlDataAdapter(command);
dataAdapter.SelectCommand = command;
dataAdapter.Fill(dataSetSource);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
connectionSource.Close();
}
try
{
connectionDest.Open();
dataSetDest = dataSetSource.Copy();
gridViewCopy.DataSource = dataSetDest;
gridViewCopy.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
connectionDest.Close();
}
}
异常: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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 提前膜拜大侠~
String connStringSource = @"server=.\SQLEXPRESS;database=Demo;Trusted_connection=True";
String connStringDest=@"server=.\SQLEXPRSS;database=DemoMate;Trusted_connection=True";
{
SqlConnection connectionSource = new SqlConnection(connStringSource);
SqlConnection connectionDest = new SqlConnection(connStringDest);