将SQL Server的.bak文件连接到visual studio [英] Connecting a .bak file of SQL server to visual studio

查看:250
本文介绍了将SQL Server的.bak文件连接到visual studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



所以我的问题在于,我已经在我的sql数据库上备份了名为'SDP',然后我在另一台新PC上恢复了sql备份文件。现在我想从新PC执行我的vb.net程序。我面临的问题是我在我的代码中写的服务器名称是我以前的PC(servernamePC1)的服务器名称。现在在新PC中,它有一个新的服务器名称。因此,如何在vb.net中设置通用连接路径以连接到我的数据库。



我给出的服务器名称是一个示例服务器名称而不是实际服务器名称。假设服务器名称(servernamePC1)是PC的第一个服务器名称。现在我必须连接到具有不同服务器名称的新PC中的数据库。那可能吗?或者我必须设置一条通用路径?



我尝试过的方法:



Hi,
So my problem over here is that, i have done back up on my sql database named 'SDP' then i have restored the sql backup file in another new PC. Now i would like to execute my vb.net program from the new PC. The problem i am facing is that the server name i have written in my codes are the server name of my previous PC("servernamePC1"). Now in the new PC, it has a new server name. Hence, how to set a universal connection path in vb.net to connect to my database.

The server name i have given down there is a sample server name not the actual server name. Assume that the server name("servernamePC1") is the first PC's server name. Now i have to connect to the database in a new pc with a different server name. Is that possible? or do i have to set a universal path??

What I have tried:

Dim con As New SqlConnection("server = servernamePC1; database=SDP; integrated security=SSPI")

推荐答案

您可以在本地计算机上尝试'localhost'作为通用服务器名称。确保SQL服务侦听地址127.0.0.1
You can try 'localhost' as generic server name on local machine. Make sure SQL services listen to address 127.0.0.1


这就是总是 将连接字符串存储在配置文件中 [ ^ ],如注释中建议的0x01AA。 :)



可能能够逃脱设置别名 [ ^ ]。但是您需要在应用程序需要运行的每台计算机上进行设置。
This is why you should always store your connection strings in your config file[^], as 0x01AA suggested in the comments. :)

You might be able to get away with setting up an alias[^] for the old server. But you would need to set that up on every computer where you application needs to run.


这篇关于将SQL Server的.bak文件连接到visual studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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