[英]Do I have to connect a SQL Server database in Visual Studio to use it in C# project?
I created a SQL Server database in SQL Server Management Studio.我在 SQL Server Management Studio 中创建了一个 SQL Server 数据库。 Now I need to connect to it in my Visual Studio 2019 C# project.
现在我需要在我的 Visual Studio 2019 C# 项目中连接到它。
Is it essential that I have to connect to the database in Visual Studio 2019?我必须连接到 Visual Studio 2019 中的数据库吗? (
Tools
>> Connect to database
menu)? (
Tools
>> Connect to database
菜单)?
Because first I got this error that I don't have permission:因为首先我收到了我没有权限的错误:
Turns out , I had to restart Visual Studio as Admin, that fixed it but next I get this error that file is in use:原来,我不得不以管理员身份重新启动 Visual Studio,修复了它,但接下来我得到这个文件正在使用的错误:
The solution to this apparently is to detach my database from SQL Server Management Studio?解决方案显然是将我的数据库与 SQL Server Management Studio 分离?
Does this mean I have to detach the database to connect to Visual Studio to connect to it?这是否意味着我必须分离数据库才能连接到 Visual Studio 才能连接到它? Do I have to attach it again in SQL Server Management Studio?
我是否必须在 SQL Server Management Studio 中再次附加它? Wonder if I will get error there then that it is being used elsewhere.
想知道我是否会在那里得到错误,然后它正在其他地方使用。
Can I just connect to the database without connecting it in Visual Studio?我可以只连接到数据库而不在 Visual Studio 中连接它吗?
What I really need is connection string but apparently I can only get that if I connect it in Visual Studio and not directly from SQL Server Management Studio.我真正需要的是连接字符串,但显然我只能在 Visual Studio 中连接它而不是直接从 SQL Server Management Studio 连接它。 Is there a way I get connection string from the SQL Server Management Studio 18?
有没有办法从 SQL Server Management Studio 18 获取连接字符串?
Like Dale K commented, I don't need to connect in visual studio and with that, googling, I was able to find this way how to get the connection string.就像 Dale K 评论的那样,我不需要在 Visual Studio 中连接,并且通过谷歌搜索,我能够找到这种方式来获取连接字符串。
The answer is there but I am posting an image of the settings and recap.答案就在那里,但我发布了设置的图像并进行了回顾。 First create a file with.udl extension (any name, anywhere on the system).
首先创建一个扩展名为 .udl 的文件(任何名称,系统上的任何位置)。 Now double click that in explorer and do the following:
现在在资源管理器中双击它并执行以下操作:
Neat thing is you can hit the test connection to make sure it connects.整洁的是你可以点击测试连接以确保它连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.