Generating an EDMX from a DB2 Database - c#

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.

Related

How Do I Connect an MVC Razor Pages Project to an MS Access Database

I created a Razor Pages Project in Visual Studio 2017.
I have an existing MS Access database with several tables.
(Courses and Sponsors).
I want to use Entity Framework to have Scaffolding create the basic CRUD pages.
I am totally lost, and I have searched for anything that will help.
I imported 2 packages using NuGet
System.Data.Odbc
MSA.NetCore.ODBC
but I have no idea how to configure a connection string and DbContext class.
Ok, pretty sure Access driver is a choice when creating a Connection.
Pick ODBC datasources> MS Access.
What threw me off was my dev computer only recognizes the old ".mdb" MS Access format.
I was looking for an MS Access driver for the ".accdb" format (newer). This is a known fault on my dev box. The correct dlls are not installed. Proof of this is I can import ".xls" files into my SSMS 2017, but not ".xlsx". This is another story for another bedtime.
My workaround was to port the MS Access tables to SQLIte, download an SQLite ODBC driver, and an SQLite browser and make a connect, using the ODBC option from VS 2017 to my project. whew.

How to get SQLite up and running in Visual Studio?

I'm having major issues trying to connect an existing SQLite database to my C# application. I've installed SQLite bundle for 32 and 64 bit, I've installed SQLite/SQL Server Compact Tools extension, installed SQLite dlls into GAC, added various different provider tags suggested by dozens of blog posts to my app.config, to my 32 bit machine config, to my 64 bit machine config. Does anybody know just what exactly does one have to do to make Visual Studio let me hook up my SQLite DB to my application?
I'm trying to add a new ADO.NET Entity Data Model to my application by using the option "EF Designer from database". I'm either getting hit with "Unable to find the requested .Net Framework Data Provider" and Visual Studio cannot even find my DB in the dialog (even though I can see it in the Server Explorer).
Or, after I've installed an additional ADO.NET SQLite as VS extension, I can see my SQLite database and test connection is sucess ful, but a soon as hit the Next button I get this:
I've installed EF only through the System.Data.Sqlite NuGet package, I'm maximally confused about this whole provider business.
Please HELP! Thanks!!!
Ok, by following a provided helpful link to a detailed guideline I was finally able to get everything up and running. I've done exactly what's described here: https://github.com/ErikEJ/SqlCeToolbox/wiki/EF6-workflow-with-SQLite-DDEX-provider
However I'm taking the liberty of providing some additional tips for anybody stumbling over the same issue.
I'm still confused about what machine config to manipulate (VS is 32 bit but I'm developing a 64 bit application), so I manipulated both without trying which one matters in that context.
The duplicate closing tag for the DbProviderFactories in the
machine config that's desribed in the mentioned github page as well
as in numerous other blogs might not always be the problem and was
not the case on my machine. But if you encounter it, clean it up
anyway.
If you apply the described changes, double check to make sure that you yourself do not introduce new duplicate tags, otherwise your Visual Studio will start up with an unusual looking start page and crahs, after fixing it all of your pinned editor and tooling windows will be gone and you'll have to re-arrange everything!
Your existing SQLite database (even if visible in the Server Explorer) might still not show up in the Choose Your Data Connection section of the Entity Data Model Wizard after hitting Next.
In that case just select New Connection..., Continue, enter your connection string there into the mask and test the connection before hitting OK. Then your database should be selected and it should work.
In case you don't know the connection string of your SQLite database, but managed to get it into the Server Explorer, you can get it by right clicking and selecting
Properties in the Server Explorer, it will show up in the Properties window.

trouble with initial setup and connection to microsoft sql server from Visual Studio

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

Visual Studio 2013 ADO.net entity model does not have Oracle data source

I've just installed visual studio 2013 and tried to setup Entity framework to access an oracle database.
I click on new ADO.NET entity model, then Generate from database, but on the data connection screen when I click "New Connection" I don't get oracle appearing the list of datasources. I only get two SQL server options.
Do I need to install something extra to get this to work?
The Oracle data source appears in my 2012 version of visual studio that I've got installed on the same machine, so not sure why it doesn't work in 2013.
it has not been released yet
https://forums.oracle.com/message/11239147#11239147
Regards.
You are using Entity Framework 6 and in its first release it only has a provider for SqlServer stuff, there is a support from external tools (DevArt) have a look at this page:
Entity Framework 6 Free Oracle Data Provider
As of Version 12.1 Release 2 Visual Studio 2013 is supported:
http://www.oracle.com/technetwork/database/windows/newfeatures-084113.html
The Oracle provider is not yet currently built against EF6 so if you are planning on using Entity Framework in MVC5, you need to install EF5 by running "Install-Package EntityFramework -Version 5.0.0" on the Package Manager Console.
If you are starting a bootstrapped MVC5 WebApp don't use the Individual User Account membership provider as it relies on EF6. You can go for one of the many alternate membership providers (http://nugetmusthaves.com/Tag/membership)
Yes. It is way more complicated that you would expect.
Go here: http://www.oracle.com/technetwork/topics/dotnet/downloads/index.html and download the appropriate installation file. (You have to create an Oracle account. You can choose a specific version of Visual Studio, or the 300+ MB download will handle multiple versions.)
Extract the zip file and run setup.exe. (I kept all the defaults.)
Click the Install button. (Close Visual Studio, by the way) After several minutes, it will finish installing.
Open Visual Studio, create new ADO.NET entity model, Generate from database, New Connection. This time hopefully you will as your Data Source: Oracle Database (ODP.NET, Managed Driver).

Connecting to a SQL Server database

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

Categories

Resources