[英]How to loop data from a table of a database from another server?
I need to get data from a table on a database on a server which I have access to. 我需要从我有权访问的服务器上的数据库中的表中获取数据。 This server is on a different area with a public IP I can use.
该服务器位于具有我可以使用的公共IP的其他区域。 I'm not really sure what I will be needing.
我不太确定自己需要什么。 It's like I need to do a CRUD GET method and return table rows.
就像我需要执行CRUD GET方法并返回表行。 Any suggestions what I can do?
有什么建议我可以做什么?
EDIT: I am using Winform and C# not ASP.NET 编辑:我使用Winform和C#不ASP.NET
If I understood well your question, you need to read a table from another Database server. 如果我很了解您的问题,则需要从另一台数据库服务器读取一个表。 If the servers are MS SQL, the easiest way is to add a connection between the servers, in SQL is a Linked Server.
如果服务器是MS SQL,最简单的方法是在服务器之间添加连接,在SQL中是链接服务器。 See this link https://msdn.microsoft.com/en-us/library/aa560998.aspx
请参阅此链接https://msdn.microsoft.com/en-us/library/aa560998.aspx
When a DB Sql Server is linked with another, you will have the possibility to access all the objects of the another server like tables, procedures and views. 当一个DB Sql Server与另一个服务器链接时,您将可以访问另一个服务器的所有对象,例如表,过程和视图。
The think you have to make attention is with transactions blocks inside stored procedures, in the server 1, calling objects from the server 2 (remote server/server linked). 您需要注意的是服务器1中存储过程中的事务块,它从服务器2中调用对象(远程服务器/服务器链接)。 Is not possible to control objects from another's servers
无法控制来自其他服务器的对象
Another way is develop an application to read the table you need and return a class with the result. 另一种方法是开发应用程序以读取所需的表并返回带有结果的类。
It will depend on what you're trying to achieve as to the best solution. 这将取决于您要达到的最佳解决方案。 The two options that would be most appropriate are...
最合适的两个选择是...
Reading data in c# to use within an application, as Greg says, put a connection string in you're app.config to the database and then use any of Entity Framework, Enterprise Library or simple .Net data library to read with relevant SQL. 就像Greg所说的那样,用c#读取数据以在应用程序中使用,将连接字符串放在您的app.config中,然后使用Entity Framework,Enterprise Library或简单的.Net数据库中的任何一个通过相关SQL进行读取。
If you've got two databases involved, one within you're network and are accessing the other one on a different network you could use multiple connection strings in the app.config or you might want to consider setting up a Linked Server within SQL Server Management Studio to the other one which would allow you to prefix the table appropriately in the SQL from the more local database connection. 如果涉及到两个数据库,则一个数据库在您的网络中,并且正在访问另一个网络上的另一个数据库,则可以在app.config中使用多个连接字符串,或者您可能要考虑在SQL Server中设置链接服务器Management Studio与另一个管理Studio兼容,这将允许您从更本地的数据库连接中在SQL中适当地为表添加前缀。 You could even use synonyms to point to the more remote table if appropriate.
如果合适的话,您甚至可以使用同义词指向更远的表。
If what you're asking is how to access a database through your c# application then sounds like you'll need to create a connection string in your app.config. 如果您要问的是如何通过c#应用程序访问数据库,那么听起来您需要在app.config中创建一个连接字符串。 Check out this article , it's pretty useful.
查看这篇文章 ,它非常有用。
<connectionStrings>
<clear />
<add name="Name"
providerName="System.Data.ProviderName"
connectionString="Valid Connection String;" />
</connectionStrings>
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.