Interface .net MVC4 with SQL Server 2005/2008 - sql-server

My organization uses IMIS, a membership/event database that stores its data in our sql server 2005 db. I've been developing classes and service layers to interface with that data using - wait for it - asp.net 1.1, and my lord I am ready to make the switch to something a little more modern.
So after experimenting with CakePHP on the side, being a microsoft shop, I'd like to use MVC4 to take care of all of my future applications, but it seems that every tutorial I find on the subject uses an SQL Server Express instance - there doesn't seem to be much mention of connecting to a remote 2005 or a remote 2008 server.
Full disclosure, I have seen a few comments here and there mentioning that the name of the class and connection string and database all have to be related, but I haven't found any clear indication of what the rule of thumb is.
If anyone can give me some basic steps as to how to set this up, I'd be forever grateful.
Thanks.

If you have existing Database you want to connect to I would suggest using Entity Framework with Database First approach.
You probably could find many tutorials, here is the one particularly for Entity Framework + Database First + MVC:
http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/database-first-approach-in-entity-framework/

Related

How can I connect to my SQL Azure-database using Microsoft Silverlight?

I have a database online at Windows Azure. I want to connect to the database and show some tables in Microsoft Silverlight. I have created a Silverlight Application and published the website on Azure here!
How do I connect to my SQL Azure database in Silverlight?
The same way as connecting to any other database!
Personally, I use EntityFramework and create my own service. You can use EF and use RIA Services to create a lot of code for you though if you prefer.
Add an Entity Model to your project, create from existing db, point at your Azure Db, job done. Remember to add your existing IP to the Azure firewall while developing.
EDIT:
Try following this tutorial instead:
http://msdn.microsoft.com/en-us/library/ee707376(v=vs.91).aspx
BUT one thing to watch out for. When you come to the step to add a DomainService, if it hasn't picked up your context you will need to follow the steps listed here:
http://support.microsoft.com/kb/2745294
... which are easy to follow. Delete the TT files and change the model code generation strategy from none to default.
One thing that you can do is create a WCF project, which will act as your Web Role in Azure.
Ideally, you may have 2-3 projects in your solution:
1) Silverlight Project (Presentation Layer)
2) WCF Project (Business Layer)
3) C# Class Project for your Sql Connections (Data Layer)
What you would be able to do is use C# .Net libraries for Sql to connect to your database. You may either execute stored procedures (Can pass in variables), which are cached in memory for faster long-term performance, or Sql queries in a string variable, to pull the exact information you want in custom queries. This would be returned to the WCF Project in which you would be able to perform any custom business-logic and you may begin to package your data into class objects. These objects may be passed back to Silverlight via a Service Reference, and you may use many familiar Silverlight tools to display your information.
The above recommendation may be a more more in-depth than that of the other recommendations, but in cases where you really need control over your data and need to apply business logic, this is a good way.
The easiest way in the world I know of to hook up a SQL Database to a Silverlight application is to use a Visual Studio LightSwitch project. There are ton's of posts on how to do this - http://blogs.msdn.com/b/lightswitch/ . Basically if you make a LightSwitch application (available in VS Professional SKUs and up), it gives you several screen templates to choose from which are all Silverlight (or HTML 5 if you choose). Then you can "attach" to an existing SQL Database such as SQL Azure just fine. And make browse or edit screens around the SQL data.
You can optionally model your own SQL Database and then "publish" it out to SQL Azure.
You can do all of this without writing any code too and provides some good basic functionality.
HTH - Matt

How To Store / Query Data In VB.NET?

At the moment I am using Access & an OleDb connection to store data. I went down this route originally because I though that this was the best way for applications that I am distributing to my clients.
I would prefer to use something like SQL Server but is this a good idea for software I am distributing? Does the average Joe's PC have SQL Server pre-installed? If not, I suppose I can provide them with a link to download it for free?
Is there any better alternatives to Access / SQL Server?
You can use SQL Server CE and bundle the database with your application.
See this How to on MSDN.
You haven't really given enough information to answer this specifically but I'll answer generally:
Does the average Joe's PC have SQL Server pre-installed?
No.
If not, I suppose I can provide them with a link to download it for free?
Yes, Microsoft has fairly generous 'free' versions of SQL server Express for small database sizes (<1GB) and small numbers of CPU's (1). Check here.
Are there any better alternatives to Access / SQL Server?
It depends on your app, your skill and how you define better.
If you are running sql-server you can very easily use linq2sql and have strongly typed data base objects that offer clean vb.net code. The linq technologies are worth learning IMO. The tools in VS2010 work well with sql-server databases. Other more modern Microsoft tools are available too that integrate very easily (entity framework and lightswitch (which I don't have experience with)).
For small local databases sqlite works well. If your project is very small and the sql is simple this is a very light weight solution. This is very small and very fast and is used everywhere.
If a server is needed and low cost matters mysqlis a solid open source server though it is now under private ownership.
Again depending upon your application off-site hosting of a database might be a viable solution. I have a client that is still running their db in the cloud with a low cost 2008 SQL Server provider.

Lightswitch and Database load - best practise

After reading through some articles on LightSwitch, I'm left wondering what prevents a LightSwitch user creating queries that over load the data-source, mainly SQL databases.
From my initial understanding, a LightSwitch user is not a developer or DB admin, and may little understanding of the impact a seemingly simple query can have on a multi-user database.
Does LightSwitch have built in governance, caching etc, is it safe to let the user have access to the last years sales data?
I don't believe there is anything built into LightSwitch for this, however this should be able to be handled on the DB server.
If you're running SQL Server 2008 they've got resource governance built in.
MSDN SQL 2008 Resource Governance
Specific example

Where can I find resources for setting up a Silverlight app that accesses sql server 2008 Express DB?

I am trying to set up a basic Silverlight application to run behind the firewall on my Windows XP machine with IIS 5.1. We have a MySQL server for production purposes, but I would like to set up SQL Server 2008 Express Edition on my Windows XP machine to host the database part of the application.
I'm completely new to a lot of .NET develoment but would like to find the resources to get started. I've checked out Silverlight.net/GetStarted/, but unless I missed something there, this step wasn't explicitly there.
Does anyone know where I could go to read about how to do this and maybe a simple walthrough of a sample Silverlight application written to access SQL Server 2008 Express?
Any suggestions and links would be much appreciated.
There are 3 options that I know of for connecting to a database from Silverlight:
WCF: Create your own WCF service with methods like GetCustomers(), UpdateCustomers() and DeleteCustomers(). Those methods are implemented on the server side, so in the background you can use LINQ to SQL or just open an old-fashioned SqlConection and run some SqlCommands against the database.
ADO.NET Data Services: This is a custom WCF service implemented by MS. You point the service at an Entity Framework class (auto generated from your custom database, super easy to create) and in turn it'll accept standard http rest commands that that do things like GetCustomers/Update/Delete. You can then add a service reference to this guy from your Silverlight app and it will auto generate 1 class per table, etc along with a client to connect to the server (http port 80 so no firewall concerns here). On the client side you're interacting with rich classes that look just like your database structure and work well with LINQ. This is not Silverlight specific and could be used from any client, even a console app.
.NET RIA Services: This is like ADO.NET Data Services but adds support for many things Silverlight including property change notification on the client side (note that the bleeding edge CTP2 of ADO.NET Data Services also implements change notifications), easy to hook events for browser navigation (i.e. you get an event when the user clicks back or forward) and code sharing between the server and the client (just name your file MyClass.shared.cs in your ASP.NET application and it magically shows up in your Silverlight client).
All of these options use http port 80 so they'll work well with your firewall. I'd really encourage you to try all 3 if you've got the time. If you don't have the time go directly to ADO.NET Data Services (grab the CTP2 you'll appreciate the new features).
Plain vanilla SL + WCF + SQL, but it's a little old:
http://msdn.microsoft.com/en-us/magazine/cc794260.aspx
Shawn Wildermuth's MSDN article is a good starting point for ADO.NET Data Services:
http://msdn.microsoft.com/en-us/magazine/dvdarchive/cc794279.aspx
This will get you up and running with good results in short time but note that it uses beta software. You'll see how many improvements have been made to ADO.NET DS since Shawn wrote that previous article:
http://blogs.msdn.com/astoriateam/archive/2009/09/01/introduction-to-data-binding-in-ctp2.aspx
And here's Brad Abram's mother of all data connectivity posts (RIA Services focus here - I think the series is up to 24 parts now):
http://blogs.msdn.com/brada/archive/2009/08/02/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-summary.aspx

Delphi - Database Server

Which of the Database servers would you people recommend for using in a moderate-to-large scale (will vary from customer to customer) application.
I know MS SQL but since the app will be developed using delphi the .net framework is kind of annoying to deploy aswell. Also how realiable is Interbase.
Thanks in advance.
Since I have been developing in Firebird for several years now, if I were in your situation, I would look no further. The fact that you can develop your own extension library (udf library) in Delphi makes it very attractive to start with. Some of the new SQL constructs like the List aggregator and Common Table Expressions are icing on the cake. Deployment is very light (under 5 MB), and the support is excellent including incredible tools like IBExpert. I used MS SQL Server in a big company I worked at a few years ago and I would choose Firebird over MS SQL Server.
Data Access to SQL Server has nothing to do with the .NET framework. Delphi can connect just fine to SQL Server.
In terms of database engines that work with delphi, another you can consider is the Sybase Advantage Database server
Interbase is as reliable as they come. In fact, I'd like to get a job as an Interbase DBA, because I could uses the sleep.
I would definitely recommend looking at Interbase by Embarcadero or the open-source sibling, Firebird. Both are very well supported by Delphi by means of native, high-performance db-access components and such.
Interbase is a totally rock-solid database - I would put it on a par with SQL Server or Oracle. It's totally capable of handling medium to high traffic for at least 50-100 users concurrently, no problem at all.
Another two worth competitor would be Elevate DB and Nexus DB. Both grew out of Delphi file-based database systems, and both have been around for quite some time (in one form or another) and are well proven, widely used, well tested.
Marc
This seems back-to-front to me. I would choose the database server first, then select the development environment that works best with the selected database.
SQL Server. For 2005, you can make your own SQL Server deployment application that automates installing of Windows Installer 3.1, .NET Framework 2.0, SQL Server 2005 then installing the database through generatated SQL script (Feel free to contact me if you need help with it, I'd gladly help you). If you still insist on not installing .Net framework which is 22MB, I'd say go with SQL Server 2000 as you can still upgrade it to 2005+ when you'd like to.
Also, I had been using Advantage Database Server for few years and it's alright, Few DLLs to copy and you're ready to go even if you'd like to switch to remote version.
Both Server and Client installations of MS SQL require the .NET framework on the target machine. That's about it. If we can use ms sql without .net on target machine then ms sql is fine.
I have being developing in Delphi for about 6 years using distinct editions of SQL Server, and this database server behaved very very well. All of them were critical applications.
So, I would recommend you to keep with it.If you don't want to use .NET with and keep SQL Server I would recommend an older version pre-2005.
This isn't really an answer, but some things you might like to consider before making your mind up.
What do you mean by moderate-to-large scale? Do you mean by the number of concurrent users or by the amount of data being stored?
Are you going to be supporting the database as well when it's deployed, or might the customer have their own DBAs and want to incorporate it into their infrastructure team's remit?
Do you need to build-in complex features like auditing or granular security that some databases might provide out-of-the-box? Do you need to be able to run an overnight batch process on the database in some controlled manner?
Do you need to be able to have robust high-volume transactional support, or is it more for just using as a sink for reporting data? i.e. is it more OLTP or OLAP?
Are you limited by cost? i.e. does it need to be free/open-source, or can you select paid-for vendor product?
Both Firebird & Interbase are great, but not generally well-received into an "enterprise" environment in my experience unless they're "hands-off" and embedded into the application. MS SQL Server is a "safe-bet" for most systems. There is a cost associated with it but, as you know, it does come with a complete toolset and very good support.
If you do go down the Firebird or Interbase route then do take a look at Jason Wharton's IBObjects library which provides a high-performance replacement for BDE when using these databases. http://www.ibobjects.com/

Resources