I installed Visual Studio 2010 and SQL Server Express 2012. Then I created a new database in SQL Server Management Studio.
Can someone tell me how to connect to this database from Visual Studio (the type of project is not relevant) and start working.
Take a look at your Server Explorer. You will be able to create data connections, and use them, from there.
On the other hand, if you asking how to create a C# program and connect to your database, that's an entirely different question, with a far more complex answer. But a little research on Google should get you started. This article might help if this is what you want to do.
There are options like if you want to add and Entity Framework to your project or you want the simple to the point connection to the database.
Well, in the second case you can follow the steps:
Go to the server Explorer>>Options to add a conection to the database>> Choose the Server Name>> and you will be guided.
For using an Entity Framework, you can go through the Entity Framework Tutorial
I don't think you would be able to connect to SQLSERVER2012 database files from VS2010 server explorer due to the version incompatibility of the database files and the VS2010..
Related
I wrote a small app to learn more about SQL and experiment with Entity Framework. On first execution, my app creates the database locally, and after that opens the existing database. So far, so good - it works pretty well on my laptop, which has SQL Server 2017 installed.
I tried copying the assemblies to my desktop machine and that also worked as expected, though SQL Server was not installed.
But when I tried copying the assemblies to another laptop, the app would not run. The exception I saw was:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The Server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 52 - Unable to locate a local Database
Runtime Installation. Verify SQL Server Express is properly installed
and that the Local Database Runtime feature is enabled.)
All machines are Windows 10. (Is it significant that the desktop machine has Visual Studio 2019 installed?)
I can't seem to find a post here which speaks to my problem. (I'm probably not phrasing my query well...)
Anyway, I don't want other users to be required to install SQL Server (Express, or otherwise). What do I need to include in my installation?
Can it be done more-or-less automatically by using ClickOnce deployment (a.k.a. Publishing Wizard)? Or do I need to build an .msi with Wix code?
Is SQLite a better option for this? Users of my app will not be sharing databases; each will have their own.
I have seen mention of SQL Server Compact Edition in this post: ASP.NET MVC - Switching from SQL Server Express to Compact Edition - Connection Issue, but when I tried to run this down, it seemed like this is no longer available from Microsoft. And I believe I'm already using SQL Server Express (looks like this is confirmed by the error message, above)...
At present I have worked around this problem by using ClickOnce deployment. In the near term, I would like to change the installation to include the dependencies (.NET & SQL runtimes) in the setup package, rather than downloading them at install-time.
But I wonder if SQLite would be a better long-term solution... One thing I have appreciated about SQLServer is that I can use SQLServer Management Studio to get at the database apart from the app, so I can validate what the app has done. I also think this is a good thing for users, as they will always have a second option for getting their data, if something goes wrong with the app.
Does SQLite provide any tool similar to SQLServer Management Studio for accessing the database?
SQLite is a better option as it is an embedded database. This means that it is a part of your application and doesn't require additional setup. It works well for storing per-user data that is not shared.
https://www.sqlite.org/whentouse.html
SQLite only requires its assemblies for deployment.
SQLite deployment for .net application
I am on a Windows 10 machine, which has Visual Studio 2015. I am now trying to do projects with a database on the same machine. I seem to have SQL server ( I am really new to Databases ) Here is why I think I have a Database, which I can use:
C:\Users\zohal>wmic product get name,version | findstr "SQL"
Microsoft SQL Server Compact 4.0 SP1 x64 ENU 4.0.8876.1
When I try to connect to a database from Visual Studio I do the following:
click on Project > Add New Data Source new Window Comes up
select Database new Window Comes up
select Dataset the only option available, new Window Comes up
select NewConnection new Window Comes up There are six options
select Micorsoft SQL Server new Window Comes up but the pulldown is blank. I looked in the services section of Computer Management application, and do not see a SQL service running. I want to know how do I connect to this SQL server and does it work for what I want to do, which is to run .Net C# code with SQL statements?
Update...........
Guys, thank you for the content and advice. I have tried both SQL compact and SQL Express, and ran into the following problems. I wonder if you can help, or perhaps I'll create a new post. I have tried everything I could think of. 1) I tried to use the SQL compact. Got as far as "Creating a SQL server Compact Database". When I right click on the "App_Data", I just don't see an option of "SQL Server Compact 4.0 Local Database" as it stated in the procedures. Here is an of what I see. I did a search online for this type of issue, and the solution was to install a tools package. I did that. In fact I ran the Visual Studio install file, and chose the modify option and added all the tools, and support packages I could think of. I rebooted the machine also; no change.
I also ended up installing SQLExpress, and followed this link to set it up, but when I click on a new connection option I do not see the SQL Express option in the server name pull down as it states in the procedure. I basically get as far as creating the project and three steps into the procedure. I can put the projects on Git if that helps. My immediate goal is to create a table and query it. Here the code in my project:
var query = from c in db.Customers
where c.City == "Nantes"
select new { c.City, c.CompanyName };
Right now, I get an error under "c" and "db" as I have not created a connection. While I don't know how to do that yet, I do know that is not a huge task. But if I can not connect to a Database, this does not help me much. I did find the right assemblies and added them to the beginning of my project. I am talking about
using System.Linq.Expressions;
using System.Data.SqlServerCe;
Just tell me what to do. Should post again or can help me?
Update: Thank you. The MVC .Net Core MVC procedures worked. Thank you so much.
SQL Server Compact is not a full fledged database service. It is a way to store data in a file and run sql like queries against it.
Here is a short walk through of how to connect to a sql compact database: https://msdn.microsoft.com/en-us/library/gg606540(v=vs.100).aspx
If you want to use an actual sql server you can download and install SQL Server Express for free. Here is a walk through for that: https://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
Both of the linked examples use Entity Framework to connect which is an ORM. There are many ways to connect to a database in C#. But since you mentioned running sql statements directly you may want to look into Dapper.Net which is a mirco ORM that let's you run SQL statements and map the results back to objects.
If you are not developing mobile (win mobile) apps, you need to download SQL server express edition which is suitable for any database application built for .NET and targeting the desktop/web apps.
To install the latest SQL express 2016, please visit this link or do some search on the web:
https://www.microsoft.com/en-us/sql-server/sql-server-editions-express
I would first verify in "Control Panel > Programs > Programs and Features" to check whether SQL Server is installed on the machine. You should see program with name "Microsoft SQL Server 20xx Setup". If you don't see any such names, then I suggest you to download and install a fresh copy of SQL Server.
Microsoft® SQL Server® 2014 Express
If you do see it in control panel, then open RUN (Windows Key + R) and type SSMS and press enter. This should open SQL Server Management Studio. (Sometimes SQL Server might be installed but Management Studio might not be. You can download Management Studio as well from the link provided above)
After opening management studio, enter the server name and click on "Connect". If you don't know server name enter . (dot) and click "Connect". Now you should be connected to SQL Server.
You should be able to connect C# code with SQL Server using a connection string.
Different formats of connection strings
How to store connection strings in web.config or app.config
Execute a command in c# by connecting to SQL Server
I'm trying to create an EDMX file using VS2013 so I can read/write from a DB2 Database. I go through the same process as creating the EDMX from my SQL tables (Right click on project -> Add New Item -> ADO.NET Entity Data Model -> EF Designer from database -> Not using SQL this time so: new connection -> Change data source) but in the Data Source option, DB2 is not available. I have 2 SQL options and that's it.
Data Source
So after doing some investigating around here along with some other places, it looks like EF wasn't actually setup to do this until a plugin for EF6 came out. So using Nuget I have installed EntityFramework.IBM.DB2 version 6.0.3 hoping that would add something to my Data Source area allowing me to choose a DB2 database but still nothing.
I'm gonna try to give as much info about my system here as I know so if I ramble...which I tend to do...sorry in advance.
I'm on Windows 7 using VS2013 Pro edition. I have an ODBC connection setup and it's been working great for years. I can go into the ODBC Manager and test my connection to both Test and Production DB2 and it connects just fine.
The ODBC Data Source Administrator is version 6.1.7601.17632 and I'm using the IBM DB2 ODBC Driver...looks like it's version 10.5.500 (although I'm not 100% sure if I'm looking in the right place to get that version number)
I can also go into Access and connect to the DB2 databases using the ODBC connection and bring back the tables and their data.
I can also write SQL statements directly into my code with the connection string setup (that I assume uses that same ODBC connection) and reads data from SQL and calls Stored Procedures connected to those DB2 tables to write/update/delete.
Lastly, it seems like a previous coworker was able to make this work. I have loaded his code and when I pull up the EDMX, I get the nice graphical display of all the tables. But when I try to click Update from Database, I get an error:
Error Message
Sadly, he is no longer with the company and his computer is not in a condition where I can take a look at it.
So it feels like this is something that can be done and that my computer is almost setup to do this...with the exception of something I'm missing that will allow me to add that DB2 type data source to that first image above so I can select it, put the credentials in and move on.
Any help will be truly appreciated...
In order to use Entity Framework and Visual Studio... you need to install IBM's drivers as well as a Visual Studio Add-in (to make DB2 show up in the dropdown of data providers and create an EDMX properly). The following is the setup we use to communicate with DB2 z/os. I am not sure whether or not these same drivers work with DB2 Linux/Unix/Windows.
http://www-01.ibm.com/support/docview.wss?uid=swg24041453
The above link is for the client version 10.5 fix pack 7. I have used this to setup both Visual Studio 2013 and Visual Studio 2015 in Windows 7/8.1 (have not tested on a Windows 10 development machine).
Here's what you will need to download and install
Data server driver package (Windows)
Database Add-ins for Visual Studio
You will also need a license file (your DBA should be able to provide this for you, or at least download one using their IBM login)
Install the data server drivers first, then the add-ins. Copy your license file to C:\Program Files\IBM\IBM DATA SERVER DRIVER\license
You will still need the EntityFramework.IBM.DB2 nuget package if you wish to use EF6, as the Visual Studio Add-ins by themselves are only compatible with EF5
Thanks for the response.
The Database Add-ins is exactly what I was looking for.
I was able to skip part 1 of your question since I already had that part done except...in order to do part 2, I had to update my drivers to the same version that I was using to install the Add-ins.
I downloaded version 10.5 and updated my drivers then I was able to install the Add-In and was able to continue and create my EDMX.
Thanks so much for the help.
I'm currently learning C# with Visual Studio 2013 and planning to write an application with Database. There i have some questions:
What's the best database to publish with my application to
friends/customers? The database won't be too big. And every user
should use his own database.
How do i publish my application with the database and make an installer from it? I want to give customers a setup.exe that they can install. With everything they need, i.e. .net, database, etc
Thanks in advance
Here is a good SQL Comparison Table that shows what you can and can't have with different options (SQL Server Express, Local DB, SQL Server Compact / CE).
You probably want SQL CE so you can bundle up an actual database file with your installer.
As for the installer, you'll need to create a Bootstrapper which will contain your installer + other installers you require + your database that you're releasing (assuming you mean a pre-populated database?).
MS SQL Server Compact edition would be a good choice. It's free and redistributable with Your application. No extra installation needed. http://www.microsoft.com/de-de/download/details.aspx?id=17876
For really small databases, you could use sqlite.
Otherwise, I'd suggest using MS SQL Server, it has a free Express edition. I don't think attaching another install.exe would cause problems.
Would anyone mind explaining (or pointing me to a tutorial) how to setup an SQL embedded server with Visual Studio Express edition?
I'm not concerned with getting the Designer tab working, but I'm trying to achieve a few basic things:
Access the database via file path
read/write to database file
password to connect to database (not too big of an issue)
The solution I've been pointed to was SQLite to do so, and have seen ADO.Net and Entity Framework to connect the file to the project. So I guess a few important aspects would be that once I set the database up with the project can I
send the projects back and forth to multiple developers?
who are on different computers who have not installed any SQL
related anything?
And is SQLite a viable solution for this?
I've been trying to get a working solution for about 7 hours now.
I suggest you, use SqlCompact 4.0 instead of Sqlite.
You can download SqlCompact 4.0 from Microsoft download center. Also you can easily transfer database between machines. Read about Private Deployment here. And finally an awesome toolbox for using SqlCompact 4.0 stand alone or addons for Visual Studio