简体   繁体   English

ASP.NET Core Web API - 使用Sybase和SQL Server实现多数据库

[英]ASP.NET Core Web API - implement multiple databases using Sybase and SQL Server

For some days now I've been trying to implement multiple databases in ASP.NET Core-6 Web API using Sybase and SQL Server.几天来,我一直在尝试使用 Sybase 和 SQL 服务器在 ASP.NET Core-6 Web API 中实现多个数据库。 I have never done this before.我以前从未这样做过。

I have this connection:我有这个连接:

  "ConnectionStrings": {
    "MssqlDbConnection": "Server=nikatic;Database=mymssql;Trusted_Connection=True; MultipleActiveResultSets=true;",
    "SybaseDbConnection": "Server=nxppawe;Database=mysybase;Port=6645;Min Pool Size=100;Max Pool Size=1000;User ID=acme;Password=lennon;charset=cp850;"
  },

I have three (3) tables:我有三 (3) 个表:

  1. Employees ---> From SQL Server员工 ---> 来自 SQL 服务器
  2. EmployeeProject --> Sybase员工项目 --> Sybase
  3. Projects --> Sybase项目 --> Sybase

I want to query the 3 tables from the two different databases and display the result.我想从两个不同的数据库中查询 3 个表并显示结果。

using System.Data;
using System.Data.SqlClient;

var sql = @"select e.EmployeeId, e.Name, e.StaffNo, e.Gender, e.DateOfBirth, p.ProjectId, p.Name, p.Duration
            from Employees e
            inner join
            EmployeeProject ep on ep.EmployeeId = e.EmployeeId
            inner join 
            Projects p on p.ProjectId = ep.ProjectId;";

How do I achieve this?我如何实现这一目标?

Thank you谢谢

Here's a link for you to create a linked server from SQL Server to ASE 12这是一个链接,供您创建从 SQL 服务器到 ASE 12 的链接服务器

https://www.cdata.com/kb/tech/sybase-odbc-linked-server.rst https://www.cdata.com/kb/tech/sybase-odbc-linked-server.rst

General doc on how to create a linked server in SSMS关于如何在 SSMS 中创建链接服务器的一般文档

https://learn.microsoft.com/en-us/sql/relational-databases/linked-servers/create-linked-servers-sql-server-database-engine?view=sql-server-ver15 https://learn.microsoft.com/en-us/sql/relational-databases/linked-servers/create-linked-servers-sql-server-database-engine?view=sql-server-ver15

Once you created it, you will be able to access any of your Sybase tables from SQL Server.创建它后,您将能够从 SQL 服务器访问任何 Sybase 表。 Note the 4-name notation for remote tables vs 3-name notation for local tables.请注意远程表的 4 名表示法与本地表的 3 名表示法。

select 
  e.EmployeeId, e.Name, e.StaffNo, e.Gender, e.DateOfBirth, p.ProjectId, p.Name, p.Duration 
from 
  nxppawe.mysybase.acme.Projects p
join nxppawe.mysybase.acme.EmployeeProject ep 
  on p.ProjectId = ep.ProjectId
join mymssql.dbo.Employees e 
  on ep.EmployeeId = e.EmployeeId
;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET Core Web API and MongoDB with multiple Collections and multiple Databases - ASP.NET Core Web API and MongoDB with multiple Collections and multiple Databases 使用 ASP.net 内核 web api 发送多个文件 - Send multiple files using ASP.net core web api 如何在同一进程中实现 ASP.NET 核心 Blazor 服务器应用程序和 Web API 应用程序? - Howto implement ASP.NET Core Blazor Server app and a Web API app in the same procress? 在 ASP.NET Core 5.0 Web API 中实现 DelegatingHandler? - Implement DelegatingHandler in ASP.NET Core 5.0 Web API? 如何在ASP.NET Core Web API中实现通过id获取? - How to implement get by id in ASP.NET Core Web API? ASP.NET中如何实现搜索过滤 Core Web API - How to implement search filter in ASP.NET Core Web API ASP.NET Core Web API - 如何使用 Fluent Validation 实现可选验证 - ASP.NET Core Web API - How to implement optional validation using Fluent Validation ASP.NET Core 2.2 Web API 项目:使用端点实现电子邮件确认回调 url - ASP.NET Core 2.2 Web API project: implement email confirmation callback url using endpoint 如何在ASP.NET Web API Core应用程序上使用QUARTZ实现调度程序? - How to implement a scheduler using QUARTZ on an ASP.NET Web API Core application? 如何使用AddMvcCore()实现“纯”ASP.NET Core Web API - How to implement a “pure” ASP.NET Core Web API by using AddMvcCore()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM