LinqPad 在同一台服务器上连接两个 azure 数据库
LinqPad connect two azure databases on same server
根据常见问题解答 (1),我可以通过多种方式将其他数据库添加到我现有的连接中。我都试过了,none 为 SQL Azure 工作。
事实上,SQL Azure 作为提供商,甚至不包括 "Include additional databases."
的选项
有人可以告诉我 LinqPad 连接两个数据库的解决方法吗?我正在尝试创建迁移 linqpad 脚本以将数据从一个数据库同步到另一个数据库。
这失败了,因为 SQL Azure 不允许您创建链接服务器。看
Can linked server providers be installed on a SQL Azure Database instance?
如果您只想将数据从一个数据库复制到另一个数据库,并且模式相同,解决方法是使用相同的 TypedDataContext 创建一个单独的连接 class:
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();
}
}
简单Select示例:
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();
}
}
根据常见问题解答 (1),我可以通过多种方式将其他数据库添加到我现有的连接中。我都试过了,none 为 SQL Azure 工作。
事实上,SQL Azure 作为提供商,甚至不包括 "Include additional databases."
的选项有人可以告诉我 LinqPad 连接两个数据库的解决方法吗?我正在尝试创建迁移 linqpad 脚本以将数据从一个数据库同步到另一个数据库。
这失败了,因为 SQL Azure 不允许您创建链接服务器。看 Can linked server providers be installed on a SQL Azure Database instance?
如果您只想将数据从一个数据库复制到另一个数据库,并且模式相同,解决方法是使用相同的 TypedDataContext 创建一个单独的连接 class:
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();
}
}
简单Select示例:
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();
}
}