Use VS2013 to browse localdb - c#

I am trying to follow along with this article (EF Code First) and whilst the code runs and the output is what I expect, I can't browse to my LocalDb from within VS2013. I see my SQL Server 2012 developer instance but not my LocalDb. I can't find my .mdf file either.
The post says I should see the database in SQL Server Object Explorer, but I can't, and it doesn't seem obvious how to add it. I know I have SQL Server 2012 installed, and some of my project require it, but to get the most from the article I'd like to be able to follow along exactly.
Any ideas how I can see my project database file from VS2013?
Jason.

Related

Create setup file from C# project with SQL server database in Visual Studio 2015

I want to create a setup file from a C# project in Visual Studio 2015 that attaches a SQL server database, and I want to run that setup file on another system and run without Visual Studio and SQL server
You are have two solutions
You should develop your application with SQL express on .NET framework or after develop with SQL Server change connection string from SQL Server to SQL express and rebuild it, be sure you create initialize DbContext class to set some data for run your application at first time with base and default data. [Such as application users and rolls and groups].
You should develop your application with dependency injection pattern [Microsoft Unity, IoC] then modify or replace one interface to change your developed application database.
Then Right click on project in solution explorer and publish it and give to customer.
The customer server has to run some kind of SQL Server if you want the SQL data to be accessed somehow. One thing you can do is to deploy your C# project with Visual Studio, export all needed tables (including their data if you want that) from whatever server you are using (for example MySQL) into a .sql file and pack everything, including instructions on how to install the sql server and your application, into a zip file and ship it to your customer.
What I do with my website application is, that I include a .bat that fetches everything from my git repository, deploys my web application on an existing IIS-Server on the current computer (with 'aspnet_compiler -f -c -u -errorstack -v /web -p "source directory" -d "target directory"' and 'iisreset /noforce') and automatically imports the SQL tables to an existing MySQL Server (with mysql --host=localhost --user=user --password=password --database=database < Backup.sql).
Sorry for that general answer, but you're question really wasn't that precise.
If you want to create a setup of your project then,
Click on Build on the top of visual studio tab and then click on Publish "yourprojectname" click on it and your setup file will be ready.
Hope this helps you
Use LocalDB,
(no need to at least open sql server management studio)
When you create Setup file add prerequisite
.net framework version
sql server (2012 -2019) express localdb
Add connection string correctly!
So from what I can gather you are looking for an easy way to distribute your database schema to clients, is that correct? If so then I don't see how you could intend to run the setup without SQL Server (without VS is fine though).
Assuming my assumption is the case then I think you need to think about a solution that will handle schema upgrades as your project develops, in which case it's essential that you move to Database Projects in Visual Studio as it will handle upgrading the schema automatically, and allow you to run change scripts for the things it can't do automatically (like when you've changed a column type or removed a column etc).
Here are some links to get you started:
Working with Database Projects (MSDN)
Introducting Database Projects for Visual Studio (youtube)
Using the knowledge that CSPROJ files are just MSBUILD scripts at the end of the day you can now publish the database project during whatever your installation/upgrade system is using msbuild which is included in the .NET framework i.e. you don't need Visual Studio.
This is by far the most robust and reliable way of dealing with database deployment. I would advise staying well clear of automated tools like Redgate, they do a great job for small projects that maybe get used in an office etc but for professional software development you need more guarantees and control.
You can try this, with Octopus deploy.
Or, you can try with Code First migration
Have you already existing database, or development starts now?

Can't use SQL Server CE in VS2012

I'm developing a web application and was trying to use a local database file to store some information. However, when I add the .sdf file, I get an error. Below are some screenshots detailing my problem.
I've been trying to figure what's wrong for several hours. I've seen similar issues, but have yet to find a fix. I used to be able to use SqlServerCe connections before with .sdf files, though that was a different development environment. I have tried reinstalling everything SQL several times, including downloading everything I could find on MSDN. Can anyone help me out?
Below is my Solution Explorer View. I've just added Database1.sdf to the project.
I get an error as soon as I add it:
If I try to open the .sdf file, I get this error:
Here is my list of references:
And, finally, all of the relevant SQL-related installations on my local machine:
SQL Server Compact 4.0 is supported by VS 2012, but requires the DDEX provider to be properly isntalled. Sounds like your VS install is somehow broken. You can install my Toolbox add-in, and go to the About dialog in the Toolbox to check if the DDEX provider and SQL Server CE 4.0 is properly installed.

How to connect Visual Studio 2010 Express C# to SQL Server Express

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)

Visual Studio Express can't change data source

I am trying to add a SQL Server data source to a C# console app.
When I try and add a new connection to my .dbml file the only Data Source available is Microsoft SQL Server Database File (sqlclient) whereas I need Microsoft SQL Server (sqlclient).
The change button is grayed out, so I can't change it.
How do I change this?
(I wondered if it was a bug, so tried uninstalling/reinstalling Visual Studio - but still no joy.)
This is actually a limitation of the Express product and you can get around it with a modification of your SQL Server connection string manually. For more information have a look at this SO Post.
I got this working by using the workaround from the post above:
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.

Add *.mdf file to C# Project

I'm using Visual Studio 2005. I create a project, not Web Project, just Windows application.
I remember that Access Database File can be added into a project. I don't need connection to server, data can be retrieved. And I want to do the same thing with SQL Database file.
I did the following steps:
Right-click on project.
Choose Add An Existing Item
Browse for *.mdf file.
DataSource Config Wizard appears and it displays this Message
An error occurred while retrieving the information from the database:
Failed to generate a user instance of SQL Server due to a failure int starting the process for the user instance. The connection will be closed.
I need help to add mdf file into my project.
To start with, and MDF file can be read only by an instance of SQL Server. If you deploy MDFs, then your application must either connect to a SQL Server provided by your end-user during setup, or it must deploy its own instance, in the later case a SQL Server Express Edition instance. See How to: Install SQL Server Express. With Visual Studio 2008 you can add a prerequisite to your own application setup MSI, see "Installing" the SQL Server 2008 Express ClickOnce Bootstrapper for Visual Studio 2008 SP1.
A second issue is that, despite the wide belief of the contrary, distributing the MDF alone without the LDF can land you into a world of pain. You can end up distributing an inconsistent MDF that needs the LDF to finish recovery and get into a consistent state.
But a more serious issue is your plan to deploy binaries (MDFs) instead of scripts for database deployment. This is doomed to fail. As soon as you'll plan to release v. 1.1 of your application you'll face the non-trivial problem of how to replace the user MDF (which now contains data added by the user) with your new MDF. This is why is much much better to deploy upgrade scripts always, and forget about the MDF in your project.
You can read from an Access file (*.mdb) in your app without any other requirements because the core Jet engine used by Access is included as part of Windows — it's built in. Sql Server is not included as part of Windows, and so you cannot use an *.mdf file in your app unless Sql Server has been installed and you have appropriate permissions for it.
It is possible to distribute either Sql Server Express Edition or Sql Server Compact Edition (recommended) with your app. Another option is SqlLite, which has a fully-managed database engine available.
An .MDF is a sql server DB, not MS Access. MS access is .MDB. You cannot read an .MDF on its own. It needs a log file (.LDF) as well. If you attach it to your local instance, it will create a new one for you. You can then connect to that DB.
To solve deployement problem (Updated version of your .mdf file and Code), you can have a utility in your application which can create .xls file of every table(Backup your database) which you used in your application. Now you can easly import those .xls file in SQL Server and create new version of .mdf file and attach same file in latest code.Now new release of your app ready to deploye..!

Categories