Connecting T-SQL to C++ or C#

Which language is preferable if Im wanting to access a T-SQL like MS Server 2008? within my code?

I know both languages probably have extensions, I do use Visual Studio 2010. However I want to know which language is probably more.....lets say "well formed" to access the database with.

Like I know C# is kinda Microsofts "thing", but I wasn't for sure. Obviously using an API that is kinda default for T-SQL is preferable, but I dont mind using Open Source.

Im more fluent in C++, but the code is relatively simple anyways.

Answers


Well, "the one you can do effectively now" would be a good start, which for you sounds like C++; I'm pretty sure both have extensive support for talking to SQL Server.

Personally I'd use C#, but that is simply because I know the libraries and tools pretty well, and could whack out a SQL call in a few seconds. I might even go so far as to suggest that the .NET libraries have seen more love lately - so maybe managed C++/CLI might help. Maybe.

It also depends on whether you can assume the client has .NET, of course...

Regardless, a simple db call should be fairly trivial - it is all those nasty corner cases that is the problem; for any platform/language, they can take experience to predict properly.

For example, in C# with a reference to System.Data.dll:

using System.Data;
using System.Data.SqlClient;
...
void SomeMethod() {
    using(var conn = new SqlConnection(connectionString))
    using(var cmd = conn.CreateCommand()) {
        cmd.CommandText = @"
           // some
           // tsql
           // here";
        // cmd.Paramaters.Add(...); // bobby tables
        conn.Open();
        cmd.ExecuteNonQuery(); // or Reader, etc - lots of options
    }
}

Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.