使用Visual Studio Express Edition连接到SQL Server

时间:2021-09-13 10:16:47

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

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

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

  4. SQL Server Database File.
  5. SQL Server数据库文件。

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

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

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#)?

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

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#).

这不是一个艰难的解决方法,但似乎很奇怪。如果Microsoft想要强制您升级到Visual Studio以连接到SQL Server,为什么它们会在其中一个免费IDE中包含该功能而不包含其他IDE?我觉得我可能会遗漏一些东西(比如在Visual C#中如何做到这一切)。

6 个解决方案

#1


20  

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.

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

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.
  • 如果您使用的是Express Edition,并且您没有使用Visual Web Developer,那么您可能正在构建一个桌面程序。

  • 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.
  • 如果你正在构建一个桌面程序,并且你正在使用快速版,那么你可能是一个业余爱好者或uISV-er在家工作而不是为公司进行开发。

  • 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.
  • 您真的不应该将服务器级数据库部署到最终用户桌面。像Sql Server Compact或MS Access这样的进程内db更合适。

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:

但是,这种逻辑并不完全适用。即使这四个点中的每一个在90%的时间都是真的,当你应用它们全部四个时它只适用于约65%的观众,这意味着高达35%的快递市场可能合法地想要谈话到服务器级数据库,这是一个重要的组。所以,简化(贪婪)版本:

  • 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.
  • 真正的数据库服务器(以及运行它的硬件)需要花费很多钱。如果您可以访问它,您应该至少能够负担标准版的visual studio。

#2


21  

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. 在Visual Web Developer Express中打开您的解决方案。它不会加载解决方案中的一些项目但是没关系。

  3. Make a new connection in Database Explorer to the required database from SQL Server.
  4. 在数据库资源管理器中建立从SQL Server到所需数据库的新连接。

  5. Add a new class library project.
  6. 添加一个新的类库项目。

  7. Add a LINQ to SQL Classes item and link it to your database.
  8. 添加LINQ to SQL Classes项并将其链接到您的数据库。

  9. Close the solution.
  10. 关闭解决方案。

  11. Open the solution in Visual C# Express.
  12. 在Visual C#Express中打开解决方案。

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

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

Update

The solution is for Visual Studio Express 2010.

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

#3


2  

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.

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

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

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

#4


2  

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.

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

#5


2  

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.

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

#6


2  

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.

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

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.

我发现了一个快速的解决方法,至少,我认为我做了因为我现在能够在tableadapters中使用我的存储过程而没有任何问题到目前为止。

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.

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

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

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

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.

它仅适用于SQL Server 2008 R2 Express实例。如果您尝试使用SQL Server 2008 R2 Workgroup,您将从Visual C#2010 Express中收到一个令人讨厌的警告,告诉您“您无法使用该连接与当前版本的Visual Studio”。当我试图修改我的一些tableadapters时,我得到了它。我切换回SQL Express实例进行开发,它再次正常工作。

#1


20  

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.

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

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.
  • 如果您使用的是Express Edition,并且您没有使用Visual Web Developer,那么您可能正在构建一个桌面程序。

  • 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.
  • 如果你正在构建一个桌面程序,并且你正在使用快速版,那么你可能是一个业余爱好者或uISV-er在家工作而不是为公司进行开发。

  • 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.
  • 您真的不应该将服务器级数据库部署到最终用户桌面。像Sql Server Compact或MS Access这样的进程内db更合适。

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:

但是,这种逻辑并不完全适用。即使这四个点中的每一个在90%的时间都是真的,当你应用它们全部四个时它只适用于约65%的观众,这意味着高达35%的快递市场可能合法地想要谈话到服务器级数据库,这是一个重要的组。所以,简化(贪婪)版本:

  • 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.
  • 真正的数据库服务器(以及运行它的硬件)需要花费很多钱。如果您可以访问它,您应该至少能够负担标准版的visual studio。

#2


21  

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. 在Visual Web Developer Express中打开您的解决方案。它不会加载解决方案中的一些项目但是没关系。

  3. Make a new connection in Database Explorer to the required database from SQL Server.
  4. 在数据库资源管理器中建立从SQL Server到所需数据库的新连接。

  5. Add a new class library project.
  6. 添加一个新的类库项目。

  7. Add a LINQ to SQL Classes item and link it to your database.
  8. 添加LINQ to SQL Classes项并将其链接到您的数据库。

  9. Close the solution.
  10. 关闭解决方案。

  11. Open the solution in Visual C# Express.
  12. 在Visual C#Express中打开解决方案。

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

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

Update

The solution is for Visual Studio Express 2010.

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

#3


2  

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.

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

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

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

#4


2  

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.

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

#5


2  

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.

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

#6


2  

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.

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

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.

我发现了一个快速的解决方法,至少,我认为我做了因为我现在能够在tableadapters中使用我的存储过程而没有任何问题到目前为止。

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.

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

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

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

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.

它仅适用于SQL Server 2008 R2 Express实例。如果您尝试使用SQL Server 2008 R2 Workgroup,您将从Visual C#2010 Express中收到一个令人讨厌的警告,告诉您“您无法使用该连接与当前版本的Visual Studio”。当我试图修改我的一些tableadapters时,我得到了它。我切换回SQL Express实例进行开发,它再次正常工作。