To use existing database on sql server2008 in visual studio 2010 mvc3 - sql-server-2008

i have an existing database on local sql server 2008.
what should i do to access the database and to display the contents of that database.
i am using visual studio 2010 and i have to make a mvc3 web application for which i have to access the database.
should i have to make model classes(entity classes) or rather can these be generated from my database. please help me with this problem.

This is a very open question and any answer will depend a lot on personal preference. I would suggest that if you are using MVC3 and VS2010 you look at Entity Framaework, Microsofts ORM (Object relational mapper).
EF MVC Tutorial
You can produce a Model from the Database or Write a Domain model that mirrors the DB using Code First its up to you the tutorial linked explains how.
Alternatives would include Nhibernate, Subsonic and a bunch of other ORMs or just doing it all your self with ado connections and commands.

Related

Reporting Services Data Model

Were still using Reporting Services for SQL2008 (not SP2). I recently started using report builder 2.0, but it looks like report builder isn't able to modify data models - and VS2010 lacks business intelligence features. My question is: Have data models been depreciated? If not, what is the current tool for managing them? I have new reports to write so I'm trying to think ahead. Can datasets be used, and access controled, for ad-hoc reporting?
There isn't a way to modify the report models using vs2010 you would still have to have vs2008 BIDS installed to be able to modify these. It looks like reports models may be depreciated from SQL 2012 (http://social.msdn.microsoft.com/Forums/en/sqlreportingservices/thread/0d0650d1-6d40-4d12-a471-54fb29b3356d).
If you starting a new project then personally I would look at using shared data sets based on views or stored procedures as these will be a lot easier to maintain and use. You can then use the permissions on these to control who has access to what.

linq to mySQL How can I trick VB Express to use it?

I'm currently using VB.NET Express to connect to mySQL over the net. No problem as long as I use plain vanilla SQL connections and statements.
But when it comes to LINQ 2 mySql, I'm struck by VB Express's limitation.
Any clue you gurus?
You'll need to switch out to using something like DBLinq, Entity Framework, or nHibernate instead of Linq-to-SQL. Linq-to-SQL only supports SQL Server and SQL Server CE. This isn't a
limitation of Visual Studio Express at all. Actually, the only limitations I know of with the express editions are that they don't support any Visual Studio plug-ins - but as far as CLR features, you aren't limited at all using Express. And, Entity Framework is built-in and available for you to use out of the box. And stackoverflow has info on the MySQL connector.
After a couple of days searching, Iv' finally reached the Saint Graal!
Since you guys at StackOverflow are so great a bunch of blokes, I've written a little how to sample for you. Here it is:
1 - The ONLY sensible, free and working product I've founr is Devart LinqConnect Express edition.
Its a free product from www.devart.com, capable of:
(Please note I have no particular links nor interest with them.)
Generating datacontext from its own embarked Devart EntityDeveloper free edition
(With some limits in number of tables per context, 10 if I'm right).
Complete the LINQ dlls into Visual Basic Express edition, without having to create a datasource from the datasource explorer.
Ok, once you've installed the package, here's the how to:
Launch the Entity designer from Program Files\Devart LinqConnect and create the model from the database.
Save the model and launch your VB Winform project.
Add the following .NET references:
Devart.Data.Linq
Devart.Data.MySql.Linq '-- Or any other DB you need
System.Data.Linq
Now add the new datacontext.designer.vb file you've created in Entity Developer
to the project:
Right-click the project in Solution Explorer and select
Add existing item
Locate the datacontext file and that's almost it!
Create a button and a datagridview named dgv1 onto your form.
5 more lines of code and you're set!
Button code:
Dim ctx As New myDataContext.myDataContext
Using ctx
Dim tbl = From xxx In ctx.myTable
Select xxx
dgv1.DataSource = xxx.ToList
End Using
The rest is pure cosmetic LOL...
It is worth to mention that although their product is great, the support is great as well!
They answered my questions in less than 12 hours.

Using SQL Server 2008 R2 with Visual Studio Express

I want to create either "LINQ to SQL" classes or use "Entity Framework" from Visual Studio Express 2010. When I attempt to add a data source my only options are:
"Microsoft Access Database File"
"Microsoft SQL Server Compact 3.5"
"Microsoft SQL Server Database File"
Do I need VS2010 Pro to use LINQ to SQL or EF? I thought I could do all of this from Express. I even went so far as to install, "Microsoft SQL Server 2008 Native Client" and it still doesn't show SQL Server 2008 as a data source.
Thanks!
p.s. I feel like a complete idiot that I cannot get this to work
LINQ to SQL (L2S) and LINQ to Entities (L2E) (aka Entity Framework) are part of the .NET Framework, and so are part of .NET regardless of what version of VS you use.
Both first appeared in 3.5 and are updated in 4.0, although LINQ to SQL won't be progressed any further in terms of functionality. Hence there isn't a dependency on the IDE. What might be missing is the LINQ to SQL or LINQ to Entity designers, but I don't think from memory they are.
If you select Add New Item and look in the Data group you should find "LINQ to SQL classes" and "ADO.NET Entity Data Model" - if not perhaps the designers are not part of Express.
[edit]
Seems this has been asked before:
Connecting to SQL Server with Visual Studio Express Editions
For LINQ, use SQLMetal to generate the spew and then just form connection string and let the code connect - you shoudldn't let VS mess with your data representation anyway. SQLMetal's spew is very clean and you can also edit it, once you learn what's what, to make it lighter - or heavier :-) - there are hooks for more code as well.
Before that check that your SQL instance is running and visible - VS installed SQL Express as default instance it can prevent real SQL's default instance from even being visible - a lot of uninstalls in your future if that happened.

LINQ to SQL vs Entity Framework for an app with a future SQL Azure version

I've got a vertical market Dot Net Framework 1.1 C#/WinForms/SQL Server 2000 application. Currently it uses ADO.Net and Microsoft's SQLHelper for CRUD operations.
I've successfully converted it to Dot Net Framework 4 C#/WinForms/ SQL Server 2008. What I'd like to do is also offer my customers the OPTION to use SQL Azure as a backend storage for their data instead of local/LAN SQL Server.
If I know SQL Azure is in my application's future, should I:
A. Switch to LINQ to SQL
or
B. Swith to Entity Framework
or
C. Stick with ADO.Net and SQLHelper
?
Thanks !
I would switch to Entity Framework, it works just fine with SQLAzure and is the recommended ORM by Microsoft for .Net 4
ADO.net works just fine,
My personal favorite is Linq2Sql which works fine with azure
Microsoft is now recommending that everyone switch to entity framework

VS2010 ultimate DataBase Project + SQL Server 2008: Updating Project from Database

this is a quick question:
I have this Database Project in a Web app solution with the real database. I want to update the database using SQL server managment studio, and then update the corresponding VS project.
This can be done?
I know that you can update the scripts in the project, but I'm not the SQL kind of guy, i rather do this changes using Mangment studio...
Thanks in advance
Update: Okay, the point is that I want to make changes (if I have to) on the database, using Sql Server Managment studio, and then update the scripts in the Visual Studio DataBase Project, instead of make my updates on those scripts, because I don't feel confortable writing SQL commands. Now what I do is to recreate everytime the Database Project (delete and then create again), this is what I want to avoid
Also, I have Visual Studio 2010 Professional.
It is very achievable in VS2010 Premium and I am currently doing what you describe with a Database Project and a Schema Comparison item.
Sigd is not correct in saying you can only compare Database/Project Compare, you can also compare Project / Database and Database / Database
You can achieve this using the Schema Compare feature, but this is only available with the Premium or Ultimate editions of Visual Studio, not the Professional edition.
In many cases this is possible using Red Gate SQL Compare Pro, although I should warn you that this is not a fully supported scenario just yet (I'm the product manager for this tool so I'd welcome your feedback if you go this route!).
Red Gate's SQL Source Control better fulfills your suggested way of working, although this won't help you just yet as we don't tie into VS Database Projects. Again, this is something we are considering for an upcoming release. You're welcome to try it and let us know what you think.
http://www.red-gate.com/products/SQL_Source_Control/index.htm
If only the Schema Compare tool did what it's name suggests.
Unfortunately it is a "Database/Project Compare". So my project which includes only a single schema, when compared with the database, generates loads of Create actions for all the other schema objects present in the database.
Nice idea, needs work.