C# LinqPad连接同一服务器上的两个azure数据库

C# LinqPad连接同一服务器上的两个azure数据库,c#,azure-sql-database,linqpad,C#,Azure Sql Database,Linqpad,根据常见问题解答(1),我可以通过多种方式向现有连接添加其他数据库。我都试过了,但没有一个适合SQLAzure 事实上,SQLAzure作为一个提供者,甚至不包括“包括其他数据库”的选项 有人能告诉我LinqPad连接两个数据库的解决方法吗?我正在尝试创建迁移linqpad脚本,以便将数据从一个数据库同步到另一个数据库 这会失败,因为SQL Azure不允许您创建链接服务器。看见 如果您只是想将数据从一个数据库复制到另一个数据库,并且模式相同,解决方法是使用相同的TypedDataConte

根据常见问题解答(1),我可以通过多种方式向现有连接添加其他数据库。我都试过了,但没有一个适合SQLAzure

事实上,SQLAzure作为一个提供者,甚至不包括“包括其他数据库”的选项

有人能告诉我LinqPad连接两个数据库的解决方法吗?我正在尝试创建迁移linqpad脚本,以便将数据从一个数据库同步到另一个数据库


  • 这会失败,因为SQL Azure不允许您创建链接服务器。看见

    如果您只是想将数据从一个数据库复制到另一个数据库,并且模式相同,解决方法是使用相同的TypedDataContext类创建单独的连接:

    void Main()
    {
        CopyFrom<Customer>("<source connection string>");
    }
    
    void CopyFrom<TTable> (string sourceCxString) where TTable : class
    {
        // Create another typed data context for the source. Note that it must have compatible schema:
        using (var sourceContext = new TypedDataContext (sourceCxString) { ObjectTrackingEnabled = false })
        {
            // Delete the rows currently in our table:
            ExecuteCommand ("delete " + Mapping.GetTable (typeof (TTable)).TableName);
    
            // Insert the rows from the source table into the target table and submit changes:
            GetTable<TTable>().InsertAllOnSubmit (sourceContext.GetTable<TTable>());
            SubmitChanges();
        }
    }
    
    void Main()
    {
    复制自(“”);
    }
    void CopyFrom(字符串源cxstring),其中TTable:class
    {
    //为源创建另一个类型化数据上下文。请注意,它必须具有兼容的架构:
    使用(var sourceContext=new TypedDataContext(sourceCxString){ObjectTrackingEnabled=false})
    {
    //删除表中当前的行:
    ExecuteCommand(“删除”+Mapping.GetTable(typeof(TTable)).TableName);
    //将源表中的行插入目标表并提交更改:
    GetTable().InsertAllOnSubmit(sourceContext.GetTable());
    提交更改();
    }
    }
    
    简单选择示例:

    void Main()
    {
        SimpleSelect("<your conn string>");
    }
    
    void SimpleSelect (string sourceCxString)
    {
        // Create another typed data context for the source. Note that it must have compatible schema:
        using (var sourceContext = new TypedDataContext (sourceCxString) { ObjectTrackingEnabled = false })
        {
            sourceContext.Assignee.OrderByDescending(a => a.CreateTimeStamp).Take(10).Dump();
            Assignee.OrderByDescending(a => a.CreateTimeStamp).Take(10).Dump();
        }
    }
    
    void Main()
    {
    简单选择(“”);
    }
    void SimpleSelect(字符串源cxstring)
    {
    //为源创建另一个类型化数据上下文。请注意,它必须具有兼容的架构:
    使用(var sourceContext=new TypedDataContext(sourceCxString){ObjectTrackingEnabled=false})
    {
    sourceContext.Assignee.OrderByDescending(a=>a.CreateTimeStamp).Take(10.Dump();
    OrderByDescending(a=>a.CreateTimeStamp).Take(10.Dump();
    }
    }
    
    无法执行文本选择:找不到类型或命名空间名称“TypedDataContext”(按F4添加using指令或程序集引用)。您知道这是在哪个命名空间下吗?似乎我缺少一个引用。注意:我还尝试了
    var ctx=new MyActualDatabaseName(“…”)
    认为这可能就是您的意思。您需要为该查询设置一个连接。将其设置为要将数据复制到的数据库。无法真正使副本正常工作,但使用简单选择的示例进行了更新。基于此,我应该能够走得更远。谢谢。乔,如果模式不匹配,你怎么做?我试图连接两个数据库,但它似乎认为它们共享相同的模式,而它们没有,所以它抛出了一个SQL异常,“无效列名”