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) 提前膜拜大侠~

解决方案 »

  1.   

    是想将:Demo数据库的一个表Copy到DemoMate数据库的一个新表中。刚才忘记了连接字符串:
    String connStringSource = @"server=.\SQLEXPRESS;database=Demo;Trusted_connection=True";
    String connStringDest=@"server=.\SQLEXPRSS;database=DemoMate;Trusted_connection=True"; 
      

  2.   

    public void GridviewCopyTable()
               {
                   SqlConnection connectionSource = new SqlConnection(connStringSource);
                   SqlConnection connectionDest = new SqlConnection(connStringDest);