What?
A simple C# connection example that you can pop into a .NET directory under IIS and run. You will have to change the parameters in the CS file to match your server credentials, etc. Anything you have to change is in brackets like this: [SERVER]
Files First: (Right-click and save)
Explanation:
Sometimes I really need to have things spelled out for me. I will always admit that I’m a horrid developer.
I was looking for a simple connection example to puke data from a MS SQL Server in C#.
I consider this action to be the ‘Hello World’ of database development.
The link below is of a neat little snippet that shows how easy this should be. However it leaves out a world of information for someone who is not familiar with .NET’s namespaces, code behinds, and the phrase ‘public partial class _Default : System.Web.UI.Page’.
http://www.jonasjohn.de/snippets/csharp/sql-connection-example.htm
The files you’ve downloaded above are a more complete example of what that link presents.
Note: I stripped out the TRY/CATCH error handling because my IIS wouldn’t compile that block for some reason.
Rant:
The world of C# can seem absurd to those of us used to PHP. There are hundreds of scripts available in the open source community that I can simply download and try out. There are even some very cool one-click installs. All designed to work off the standard install of PHP. (And if you download XAMPP it’s that much easier)
.NET is a different animal. Even downloading a ready made example can lead to hours of trouble shooting. Often only to find the answer in a forum post completely unrelated to what you’re working on.
This is great info to know.