使用 Visual Studio Express 版本连接到 SQL Server

发布于 2024-07-07 18:24:33 字数 554 浏览 8 评论 0原文

我觉得奇怪的是,在 Visual C# 2008 Express 版本中,当您使用数据库资源管理器时,您的选项是:

  1. Microsoft Access
  2. SQL Server Compact 3.5 和
  3. SQL Server 数据库文件。

但是,如果您使用 Visual Web Developer 2008 Express,则可以连接到常规 SQL Server、Oracle、ODBC 等。

对于开发需要与 SQL Server 数据库通信的命令行或其他 C# 应用程序的人来说,您真的需要使用一个 IDE (Visual Web Developer) 构建 LINQ/数据访问代码,并在另一个 IDE (Visual C#) 中构建程序?

这不是一个困难的解决方法,但看起来很奇怪。 如果 Microsoft 想要强制您升级到 Visual Studio 以连接到 SQL Server,为什么他们会在其中一个免费 IDE 中包含该功能,而不是在另一个 IDE 中呢? 我觉得我可能错过了一些东西(比如如何在 Visual C# 中完成这一切)。

I find it odd that in Visual C# 2008 Express edition, when you use the database explorer, your options are:

  1. Microsoft Access
  2. SQL Server Compact 3.5, and
  3. SQL Server Database File.

BUT if you use Visual Web Developer 2008 Express, you can connect to a regular SQL Server, Oracle, ODBC, etc.

For people developing command-line or other C# apps that need to talk to a SQL Server database, do you really need to build your LINQ/Data Access code with one IDE (Visual Web Developer) and your program in another (Visual C#)?

It's not a hard workaround, but it seems weird. If Microsoft wanted to force you to upgrade to Visual Studio to connect to SQL Server, why would they include that feature in one of their free IDEs but not the other? I feel like I might be missing something (like how to do it all in Visual C#).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

面犯桃花 2024-07-14 18:24:33

您应该能够选择 SQL Server 数据库文件选项来获取正确类型的数据库(system.data.SqlClient 提供程序),然后手动更正连接字符串以指向您的数据库。

我认为这些数据库选择背后的原因可能是这样的:

  • 如果您使用的是 Express Edition,并且您没有使用 Visual Web Developer,那么您可能正在构建一个桌面程序。
  • 如果您正在构建一个桌面程序,并且使用的是 Express 版本,那么您可能是一个业余爱好者或在家工作的 uISV-er,而不是为公司进行开发。
  • 如果您不是为公司开发,那么您的应用程序可能是面向最终用户的,并且您的数据存储可能位于他们的本地计算机上。
  • 您确实不应该将服务器级数据库部署到最终用户桌面。 进程内数据库(例如 Sql Server Compact 或 MS Access)更合适。

然而,这个逻辑并不完全成立。 即使这 4 点中的每一点在 90% 的情况下都是正确的,当您应用所有这四点时,它只适用于大约 65% 的受众,这意味着高达 35% 的快递市场可能有理由想要谈论到服务器级数据库,这是一个重要的群体。 因此,简化(贪婪)版本:

  • 真正的数据库服务器(以及运行它的硬件)需要花费真金白银。 如果您可以使用它,您应该至少能买得起 Visual Studio 标准版。

You should be able to choose the SQL Server Database file option to get the right kind of database (the system.data.SqlClient provider), and then manually correct the connection string to point to your db.

I think the reasoning behind those db choices probably goes something like this:

  • If you're using the Express Edition, and you're not using Visual Web Developer, you're probably building a desktop program.
  • If you're building a desktop program, and you're using the express edition, you're probably a hobbyist or uISV-er working at home rather than doing development for a corporation.
  • If you're not developing for a corporation, your app is probably destined for the end-user and your data store is probably going on their local machine.
  • You really shouldn't be deploying server-class databases to end-user desktops. An in-process db like Sql Server Compact or MS Access is much more appropriate.

However, this logic doesn't quite hold. Even if each of those 4 points is true 90% of the time, by the time you apply all four of them it only applies to ~65% of your audience, which means up to 35% of the express market might legitimately want to talk to a server-class db, and that's a significant group. And so, the simplified (greedy) version:

  • A real db server (and the hardware to run it) costs real money. If you have access to that, you ought to be able to afford at least the standard edition of visual studio.
不再让梦枯萎 2024-07-14 18:24:33

解决方法:

  1. 在 Visual Web Developer Express 中打开您的解决方案。 它不会加载解决方案中的某些项目,但没关系。
  2. 在数据库资源管理器中从 SQL Server 建立与所需数据库的新连接。
  3. 添加一个新的类库项目。
  4. 添加 LINQ to SQL Classes 项并将其链接到您的数据库。
  5. 关闭解决方案。
  6. 在 Visual C# Express 中打开解决方案。

现在您有了一个 LINQ to SQL 类库,它链接到 Visual C# Express 中的 SQL Server 数据库。

更新

该解决方案适用于 Visual Studio Express 2010。

Workaround:

  1. Open your solution in Visual Web Developer Express. It will not load some of the projects in the solution but it is ok.
  2. Make a new connection in Database Explorer to the required database from SQL Server.
  3. Add a new class library project.
  4. Add a LINQ to SQL Classes item and link it to your database.
  5. Close the solution.
  6. Open the solution in Visual C# Express.

Now you have a LINQ to SQL classes library that is linked to your SQL Server database in Visual C# Express.

Update

The solution is for Visual Studio Express 2010.

他夏了夏天 2024-07-14 18:24:33

我的猜测是,使用 VWD,您的解决方案更有可能部署到第三方服务器,其中许多服务器不允许动态附加 SQL Server 数据库文件。 因此允许其他连接类型。

IDE 行为的这种差异是升级到完整版本的关键原因之一。

My guess is that with VWD your solutions are more likely to be deployed to third party servers, many of which do not allow for a dynamically attached SQL Server database file. Thus the allowing of the other connection type.

This difference in IDE behavior is one of the key reasons for upgrading to a full version.

哥,最终变帅啦 2024-07-14 18:24:33

如果您使用它来获取 LINQ to SQL(我为 Visual Developer 做的和想要的),1)获取免费的 Visual WEB Developer,使用它连接到 SQL Server 实例,创建 LINQ 接口,然后将生成的文件复制到你的 Vis-Dev 项目(我不使用 VD,因为它听起来很有趣)。 仅包括 *.dbml 文件。 Vis-Dev 环境将需要一两秒钟来识别支持文件。 这是一个额外的步骤,但肯定比手动完成或完全放弃或更糟糕的是付费更好。 哞哈哈哈哈。

If you are using this to get a LINQ to SQL which I do and wanted for my Visual Developer, 1) get the free Visual WEB Developer, use that to connect to SQL Server instance, create your LINQ interface, then copy the generated files into your Vis-Dev project (I don't use VD because it sounds funny). Include only the *.dbml files. The Vis-Dev environment will take a second or two to recognize the supporting files. It is a little extra step but for sure better than doing it by hand or giving up on it altogether or EVEN WORSE, paying for it. Mooo ha ha haha.

清浅ˋ旧时光 2024-07-14 18:24:33

我能够让 C# Express 2008 正常工作的唯一方法是移动数据库文件。 因此,我打开 SQL Server Management Studio,删除数据库后,将文件复制到项目文件夹中。 然后我将数据库重新连接到管理工作室。 现在,当我尝试附加到本地副本时,它可以工作。 显然,您不能多次使用同一个数据库文件。

The only way I was able to get C# Express 2008 to work was to move the database file. So, I opened up SQL Server Management Studio and after dropping the database, I copied the file to my project folder. Then I reattached the database to management studio. Now, when I try to attach to the local copy it works. Apparently, you can not use the same database file more than once.

屋檐 2024-07-14 18:24:33

为了方便起见,我只是碰巧在 Windows 窗体中启动了我的家庭业务应用程序。 我目前正在使用 Visual C# Express 2010 / SQL Server 2008 R2 Express 来开发它。 我遇到了与 OP 相同的问题,我需要连接到 SQL 服务器的实例。 我在这里跳过详细信息,但该数据库将是在 2-3 台计算机之间同步的合并数据库,这些计算机也将使用我现在正在开发的应用程序。

我找到了一个快速的解决方法,至少我认为我做到了,因为我现在可以在表适配器中使用我的存储过程,到目前为止没有任何问题。

我将在工作中的另一个项目(VS2010 Premium)中使用的 SQL 连接复制粘贴到 app.config 中,并更改了我需要的所有内容。 当我返回到 Settings.settings 时,我只需确认我想要 app.config 文件中的内容。 我看到的唯一缺点是您无法“测试”连接,因为当您进入连接字符串的配置时,您无法去任何地方,因为“SQL Server”不是一个选项。 另一个缺点是您需要手动输入所有内容,因为您无法使用任何向导来使其工作。

我不知道我是否应该这样做,但至少我现在可以连接到我的 SQL 服务器:)。

编辑:

它仅适用于 SQL Server 2008 R2 Express 实例。 如果您尝试使用 SQL Server 2008 R2 Workgroup 及更高版本,您会收到来自 Visual C# 2010 Express 的令人讨厌的警告,告诉您“您无法在当前版本的 Visual Studio 中使用该连接”。 当我尝试修改我的一些表适配器时,我得到了这一点。 我切换回 SQL Express 实例进行开发,它再次运行良好。

I just happened to have started my home business application in windows forms for the convenience. I'm currently using Visual C# Express 2010 / SQL Server 2008 R2 Express to develop it. I got the same problem as OP where I need to connect to an instance of SQL server. I'm skipping details here but that database will be a merged database synched between 2-3 computers that will also use the application I'm developing right now.

I found a quick workaround, at least, I think I did because I'm now able to use my stored procedures in tableadapters without any issues so far.

I copy pasted an SQL connection that I used in a different project at work (VS2010 Premium) in the app.config and changed everything I needed there. When I went back to my Settings.settings, I just had to confirm that I wanted what was inside the app.config file. The only downsides I can see is that you can't "test" the connection since when you go inside the configuration of the connection string you can't go anywhere since "SQL Server" is not an option. The other downside is that you need to input everything manually since you can't use any wizards to make it work.

I don't know if I should have done it that way but at least I can connect to my SQL server now :).

EDIT :

It only works with SQL Server 2008 R2 Express instances. If you try with SQL Server 2008 R2 Workgroup and up, you'll get a nasty warning from Visual C# 2010 Express telling you that "you can't use that connection with the current version of Visual Studio". I got that when I was trying to modify some of my tableadapters. I switched back to an SQL Express instance to develop and it's working fine again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文