是否可以从一个SQL服务器读取然后使用C#从完全不同的SQL服务器读取数据? [英] Is it possible to read from one SQL server then read data from an entirely different SQL server using C#?

查看:49
本文介绍了是否可以从一个SQL服务器读取然后使用C#从完全不同的SQL服务器读取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用用户输入我通过string.format生成了一个字符串来访问sql server然后使用SqlAdapter运行我的SQL查询,最后将其传递给DataTable以便稍后显示。



现在的问题是我想访问多个服务器以从每个服务器获取相同的数据(所有服务器上的列名都相同)。



我尝试过:



Using the users input I've generated a string via string.format to access the sql server then used SqlAdapter to run my SQL Query and finally pass that to a DataTable to be displayed later.

The problem now is that I want to access multiple servers to get the same data from each of them (column names are the same on all servers).

What I have tried:

for(int i =0;i< dataList.Count;i++)
{
connectionString = string.Format(theString, data); //address for the server "data:-is the server id"

// [this area here is where I use my sql query]

}

推荐答案

有很多方法可以解决这个问题。



0)你可以创建一个用不同的连接字符串初始化的ado类(继承自提供查询功能的基类)



1)你可以创建一个静态类,该方法允许您将服务器指定为每个查询的参数



2)等等......



3)等等......
There are a number of ways you can handle this issue.

0) you can create an ado class that is initialized with a different connection string (inheriting from a base class that provides query functionality)

1) You can create a static class that has a method that allows you to specify the server as a parameter for every query

2) and so on...

3) and so forth...


这篇关于是否可以从一个SQL服务器读取然后使用C#从完全不同的SQL服务器读取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆