As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I find it odd that in Visual C# 2008 Express edition, when you use the database explorer, your options are:
Microsoft Access
SQL Server Compact 3.5, and
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#).
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.
Workaround:
Open your solution in Visual Web Developer Express. It will not load some of the projects in the solution but it is ok.
Make a new connection in Database Explorer to the required database from SQL Server.
Add a new class library project.
Add a LINQ to SQL Classes item and link it to your database.
Close the solution.
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.
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.
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.
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.
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.
Related
I'd like to ask you about the simplest way how to have a small database with my application in c#, without using a server. Im using Visual Studio 2013 Professional and I used to work with Local Database and Ado.Net data entity model, but I can't see it here anymore.
Thank you guys
You can use LocalDB.
LocalDB is created specifically for developers. It is very easy to
install and requires no management, yet it offers the same T-SQL
language, programming surface and client-side providers as the regular
SQL Server Express. In effect the developers that target SQL Server no
longer have to install and manage a full instance of SQL Server
Express on their laptops and other development machines. Moreover, if
the simplicity (and limitations) of LocalDB fit the needs of the
target application environment, developers can continue using it in
production, as LocalDB makes a pretty good embedded database too.
Here's a walkthrough: https://msdn.microsoft.com/en-us/library/ms233763.aspx
I am building a desktop application where it uses a local database file (.mdf). Since I was developing it on my machine I used SQL Management 2008 R2 SP2. Then I sent it out to others for feedback. But unfortunately they were not able to use it as they didn't have SP2 installed.
So, as a resolution, I want to include a sql file that would run while installing the application. I was wondering if someone could direct me how to do so.
What I have and what I think should be done is:
- Main Project (includes forms and classes - I have this working already)
- Setup Project (includes msi file that checks database existence and runs sql file accordingly - I need help on this)
I suggest you using wix to create the msi.
You know, you can no longer create setup project using visual studio (Version 2012 above). It has been removed completely.
So you should consider going in WIX (Windows Intaller XML) direction.
If you like the idea here is the quick and easy solution:
http://www.codeproject.com/Articles/331368/WIXDataBase
http://wix.tramontana.co.hu/tutorial/sql/creating-a-database
But its completely up to you to think about the alternatives.
Is there any real workaround to getting the Express edition of C# connected to database options other than the lightweight options allowed (Access, SQL Compact, or SQL file)? As has been noted elsewhere, it's possible in the web edition to do so. It has also been noted that you can create a project file, open it in the web edition, create a connection, and create a project with your database entities, and then switch back to C#.
However, as a workaround this is quite clunky, as it seems like if I could just get the SQL connection persisted in my C# Database Explorer, which seems to be tied to the application, not any project, then I would permanently be able to add to the database without having to constantly switch back and forth.
Has anyone worked through this problem?
I figured out a better workaround. The application settings seem to be saved in [Documents and Settings]\[User]\Application\Microsoft\VCSExpress\10.0 and VWDExpress\10.0. What I found is copying ServerExplorer\DefaultView.SEView from the VWDExpress to VCSExpress after creating the connection in WD worked perfectly. I could from there create new objects, refresh from the data, create a database from the design, etc.
yes get the .net connector:
http://dev.mysql.com/downloads/connector/net/
Use add reference to point the dll and use their functions to connect to a mysql server
Ok Just to be clear about all this...
I am on Windows 7 and am admin on my machine.
You may have to change permissions on the following folders in the usual way.
I have visual Studio c# express edition on my machine together with Visual Web developer express.
I cannot browse my local SQL server with c# express and connect to a database.
So I followed the above method.
Open an ordinary explorer window and browse to:
C:\Documents and Settings\YOURUSERNAME\Application Data\Microsoft\VCSExpress\10.0\ServerExplorer
rename DefaultView.SEView to DefaultView.SEViewORIGINAL
Open another explorer window and browse to:
C:\Documents and Settings\YOURUSERNAME\Application Data\Microsoft\VWDExpress\10.0\ServerExplorer
Copy DefaultView.SEView and paste it into the folder in the other explorer window.
You will now have 2 files in the folder
DefaultView.SEViewand
DefaultView.SEViewORIGINAL
If you open visual studio c# express 2010 you will now see your databases.
You will not be able to create a new one to that database though.
You will have to create any new connections in VWDExpress first and repeat the process.
Someone might want to check out how to just move the differences between these files and fix it that way.
Good luck
Yet another work around.
Sorerons solution only works for local databases. You will get the dreaded...'your version cannot connect ...blah blah blah'.
So I opened the project in VWD...connected using Linq to sql classes.
Voila,it worked. I had the project opened in both vde and vwde at the same time.(I was in the process of copying the project templates from my vis developer express to vis webd at the same time)
I want to learn webservice development using c# and a free database. Could someone tell me what is the best free database solution to work with c#?
thanks
Microsoft have a free version of their SQL Server database which is SQL Express. Also they recently released a new Embedded Database which is worth checking out. MySQL and SQLite are other popular choices.
As far as web service development in .NET is concerned WCF is the recommended way.
While learning, just stick to the visual studio ide and utilize the integration with iis and sql express which should be already installed. web services in C# need iis (due to .net framework requirement for c#) plus the visual studio ide is easyily integrated with sql express. after you get some learning in, you can move towards installing and connecting to other databases like MySQL or PostgreSQL ect..
There is also sql express and sql ce
I use MySQL with c# and Entity Framework every day. It works great, and you won't be limited by the express edition of SQL Server that way.
this is my first post in stackoverflow, I've always checked this site by searching in google, so I decided to join it myself! I hope to be useful to others
I'm a 3d developer (DirectX), but recently I've started making an SMS gateway using C# and SQL Express, now I'm going to create a setup file for my project (which uses .NET 3.5), what are my options? I've heard that VS 2008 can make setup, is there any sample? how can I include SQL express in my setup app?
also I've downloaded Install Shield 2010 which has a built-in support for VS 2008, I want to make my setup in a way that it detects SQL on target system and if it finds SQL already installed, doesn't try to install it again (the same rule can be applied for .NET), what are my options? how can I make such a setup file?
thanks
With Microsoft's Visual Studio, there is an inbuilt Setup Template which you can use.
Click Once
For your scenario you should take a look at Adding Click once Custom Prerequisites.
Setup And Deployment Application
For your scenario you should take a look at the Walk-through.
Or as you mentioned you have InstallSheild 2010 then:
Install Shield Wizard
Take a look at this Walk-through with Limited Edition
As for SQL Server i think you can usually go as far as SQL Server Compact Edition. (For anything greater you may need to Inform User to install it himself)
I have no personal experience with it, but SQL Server 2008 Compact might be good for this. It is an embedded solution so so you don't actually need to install a server. Alternatively you could look at SQLite, which has native .NET implementations (google for "sqlite .net").