vb.net 两个不同数据库文件之间的SQL连接查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17377186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:04:52  来源:igfitidea点击:

SQL join Query Between Two Different Database File

sql-servervb.netmdf

提问by Narendra

I am creating a Windows application which have two SQL Server databases. One is in application/startup path and other is in different drive.

我正在创建一个具有两个 SQL Server 数据库的 Windows 应用程序。一个在应用程序/启动路径中,另一个在不同的驱动器中。

I have two SQL Server database files with different names. Both are in different location. There are same tables in both databases. I want toe create a join query between tables for different database.

我有两个不同名称的 SQL Server 数据库文件。两者在不同的位置。两个数据库中有相同的表。我想在不同数据库的表之间创建连接查询。

So it is possible or not? If yes then how? This is my first question in stack over flow so please help me.

那么有可能吗?如果是,那么如何?这是我在堆栈溢出中的第一个问题,所以请帮助我。

回答by dixpac

If your databases are on same sql server instances there is no need to create linked servers(because it will hurt performance),you can simply reference table with [DBName].[Schema].[TableName]. If you have same database with 2 files sql will handle that for you If you have 2 instances than you could create linked servers or handle that in applicaiont(join 2 result sets)

如果您的数据库在相同的 sql server 实例上,则无需创建链接服务器(因为它会影响性能),您可以简单地使用 [DBName].[Schema].[TableName] 引用表。如果您有包含 2 个文件的相同数据库,sql 将为您处理如果您有 2 个实例,则您可以创建链接服务器或在应用程序中处理它(加入 2 个结果集)

回答by logixologist

As far as I am aware you cannot directly access an MDF file using VB.NET. It needs to be a SQL Server Setup importing that MDF File first. THat is also going to be a challenging taak since you really cant just point SQL to an MDF file.

据我所知,您不能使用 VB.NET 直接访问 MDF 文件。它需要是 SQL Server 安装程序首先导入该 MDF 文件。这也将是一项具有挑战性的任务,因为您真的不能将 SQL 指向 MDF 文件。

http://www.daniweb.com/software-development/vbnet/threads/115645/connecting-to-an-.mdf-database

http://www.daniweb.com/software-development/vbnet/threads/115645/connecting-to-an-.mdf-database

Other people have said you can do it. I recommend getting SQL Server 2008 Express which is free. http://www.microsoft.com/en-us/download/details.aspx?id=23650

其他人说你可以做到。我建议获得免费的 SQL Server 2008 Express。 http://www.microsoft.com/en-us/download/details.aspx?id=23650

If you setup 2 servers with a linked server all you will need to do is

如果您使用链接服务器设置 2 个服务器,您需要做的就是

SELECT * FROM TableName t JOIN LinkedServerName.DatabaseName.dbo.TableName on ...