各位大哥,帮帮小妹!!!关于两个数据库之间的连接问题!

liuzeru 2005-05-18 04:53:26
两个数据库分别在两个不同的机子上,想把他们连接起来,实现同时查询,可能吗?
1、sid:prince
ip:192.168.0.1
2、sid:princess
ip: 192.168.0.2
可不可以实现 select a.*,b.* from prince.tablename a,princess.tablename b

听说建立dblink可以,但怎么建?不会建!
...全文
103 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
凨叔 2005-05-18
  • 打赏
  • 举报
回复
sp_helpserver:
Reports information about a particular remote or replication server, or about all servers of both types. Provides the server name, the server's network name, the server's replication status, the server's identification number, collation name, and time-out values for connecting to, or queries against, linked servers.

sp_addlinkedserver:
Creates a linked server, which allows access to distributed, heterogeneous queries against OLE DB data sources. After creating a linked server with sp_addlinkedserver, this server can then execute distributed queries. If the linked server is defined as Microsoft® SQL Server™, remote stored procedures can be executed.

sp_addlinkedsrvlogin
Creates or updates a mapping between logins on the local instance of Microsoft® SQL Server™ and remote logins on the linked server.

pengchengzhi 2005-05-18
  • 打赏
  • 举报
回复
上面的能解释一下?
凨叔 2005-05-18
  • 打赏
  • 举报
回复
提供一段创建本地连接linkedserver的代码。

string strSQL;
SqlConnection conn;
SqlCommand comm;
SqlDataAdapter da;
DataTable tb;

string strServer = "127.0.0.1";
string strUser = "sa";
string strPwd = "123456";

conn = new SqlConnection(......);
strSQL = "exec sp_helpserver";
da = new SqlDataAdapter(strSQL, conn);
tb = new DataTable();
da.Fill(tb);

strSQL = "";
if(tb.Select("name='" + strServer + "'").Length<=0)
{
strSQL += "EXEC sp_addlinkedserver @server = '" + strServer + "', @srvproduct = 'SQL Server' ";
}
strSQL += "EXEC sp_addlinkedsrvlogin @rmtsrvname='" + strServer + "', @useself='false', @rmtuser='" + strUser + "', @rmtpassword='" + strPwd + "'";
comm = new SqlCommand(strSQL, conn);
comm.ExecuteNonQuery();
blackhero 2005-05-18
  • 打赏
  • 举报
回复
http://www.unix366.com/hgcxs/vngbosudqw/3377.htm
blackhero 2005-05-18
  • 打赏
  • 举报
回复
dblink
是什么呀
liuzeru 2005-05-18
  • 打赏
  • 举报
回复
这倒是,但是我不会用dblink,以前有人提过,我对dblink有强烈的好奇心,不知道它可以怎样解决这个问题
aspdotnet2005 2005-05-18
  • 打赏
  • 举报
回复
强烈关注,
china2001ok 2005-05-18
  • 打赏
  • 举报
回复
i think so
time_is_life 2005-05-18
  • 打赏
  • 举报
回复
you can execute directly

but you can execute two queries and put the datas into a dataset

then in the dataset
you can do whatever you want

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧