visual-studio 使用 Visual Studio 创建 SQL 数据库并添加到项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/773913/
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-10-22 10:23:35  来源:igfitidea点击:

Create SQL Database and add to project using Visual Studio

sql-serverdatabasevisual-studiovisual-studio-2005

提问by Max Schmeling

When I go to the 'Add New Item' window in Visual Studio 2005 and try to add a SQL Database it hangs for a bit and then give the following error:

当我转到 Visual Studio 2005 中的“添加新项目”窗口并尝试添加 SQL 数据库时,它会挂起一段时间,然后出现以下错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)

与 SQL Server 建立连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:TCP 提供者,错误:0 - 由于目标机器主动拒绝,无法建立连接。)

I can use SQL Server Management Studio to connection to localhost (default instance) just fine, but Visual Studio must be trying to connect to another instance (that isn't running anymore). How do I change what instance it tries to connect to in order to add and use the database?

我可以使用 SQL Server Management Studio 连接到本地主机(默认实例)就好了,但 Visual Studio 必须尝试连接到另一个实例(不再运行)。如何更改它尝试连接的实例以添加和使用数据库?

采纳答案by TheTXI

It sounds like you may be trying to add an instance of an SQL Server Express database but you may not have that service installed or turned on.

听起来您可能正在尝试添加 SQL Server Express 数据库的实例,但您可能没有安装或打开该服务。

回答by cdonner

Were you able to resolve this? I just spent 3 hours on the very same problem and can't say for sure what the solution was, but it works. My mistake was that the local SQL Server instance was not running when I 'upgraded' Visual Studio to the database edition. SQLExpress is not installed.

你能解决这个问题吗?我只是在同样的问题上花了 3 个小时,不能确定解决方案是什么,但它有效。我的错误是当我将 Visual Studio“升级”到数据库版本时本地 SQL Server 实例没有运行。未安装 SQLExpress。

After starting the database, I initially got the same error as you when I tried to open existing database projects or create a new database project in Visual Studio. I googled it for a long time, tried all combinations of server, instance, host, alias, and other names for the design time validation database setting, all to no avail. It would not connect. I even reinstalled Visual Studio, which did not help, either.

启动数据库后,当我尝试在 Visual Studio 中打开现有数据库项目或创建新数据库项目时,最初遇到与您相同的错误。我在谷歌上搜索了很长时间,为设计时验证数据库设置尝试了服务器、实例、主机、别名和其他名称的所有组合,但都无济于事。它不会连接。我什至重新安装了 Visual Studio,这也没有帮助。

I think what might have done the trick was a note in this msdn article- unload the project after changing this setting. I ended up clearing the field (for the default instance), unloaded the project, reloaded it, and violá, I am in business. Time to go to bed now.

我认为可能已经完成的技巧是这篇 msdn 文章中的注释- 在更改此设置后卸载项目。我最终清除了该字段(对于默认实例),卸载了项目,重新加载了它,violá,我在做生意。现在该睡觉了。

回答by Ed Guiness

Expand the Servers node and remove the old server.

展开服务器节点并删除旧服务器。

回答by SteveC

Do you get the warning dialog pointing at ... http://go.microsoft.com/fwlink/?LinkId=49251? My VS2005 dev machine has SQL Server Developer edition, but no SQL Express and I get that error when I try and add new SQL database

您是否收到指向 ... http://go.microsoft.com/fwlink/?LinkId=49251的警告对话框 ?我的 VS2005 开发机器有 SQL Server Developer 版本,但没有 SQL Express,当我尝试添加新的 SQL 数据库时出现该错误