1

I am looking for a free cross-platform (Windows, Linux) C++ library for an access to an MS SQL server DB.

For example, I want to convert the following C# flow to unmanaged C or C++ (from here) :

static void Main()
{
    string connectionString = 
       ConsoleApplication746.Properties.Settings.Default.ConnectionString;
    using (SqlConnection con = new SqlConnection(connectionString))
    {
        con.Open();
        using (SqlCommand command = 
           new SqlCommand("SELECT TOP 2 * FROM Dogs1", con))
        using (SqlDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                 Console.WriteLine("{0} {1} {2}", reader.GetInt32(0),
                    reader.GetString(1), reader.GetString(2));
            }
        }
    }
}
6
  • @Igor: How about using SQLite? Commented Mar 29, 2011 at 15:34
  • Isn't SQLite an implementation of a DB, and not a library to access an existing DB? Commented Mar 29, 2011 at 15:46
  • @Igor Oks: you are creating confusion here because you don't tell us which SQL db you are talking of. Microsoft SQL Server, Oracle, Sybase, IBM DB2, ... ??? Or are you looking for a generic library for different DB vendors? Commented Mar 29, 2011 at 16:05
  • Why do some people think MS has invented the word "sql server"? Commented Mar 30, 2011 at 11:26
  • 1
    @Doc Brown: Yes, really. SQL Server®. microsoft.com/About/Legal/EN/US/IntellectualProperty/Trademarks/… Commented Apr 14, 2011 at 15:14

5 Answers 5

4

Try DTL or SOCI.

Edit: or OTL.

Sign up to request clarification or add additional context in comments.

Comments

1

Accessing MS SQL server from windows should not be a problem in general. For accessing it from Linux, this web page may help you to find a way

http://www.sommarskog.se/mssqlperl/unix.html

Finding a solution that works on both Windows and Linux is a task that may not be solved easily, depends on the exact requirements and your current architecture. For example, when you just need C++ program calling a Perl script which does the DB work for you, this path may provide you with a free cross-platform solution. Perl is free and cross-platform, and the DBI modules too.

On the other hand, when your cross-platform C++ program uses a cross-platform framework like Qt, and you need a direct connection in your C++ program to the SQL server, ODBC may be the best option:

http://doc.qt.nokia.com/4.7/sql-driver.html

Unfortunately, according to the information behind my first link, there are no free ODBC drivers for Linux, so you might bite the bullet and buy one.

Comments

1

There is no reason to rewrite perfectly good, tested, working code.

Don't do it. Use Mono to run your existing code on Unix/Linux instead.

Comments

0

Indeed, SQLite is an implementation of a DB where data is stored in a flat file.

I think ODBC might be the technology you're looking for.

Comments

0

What about SQLAPI++? Works both on Windows and Linux/Unix. http://www.sqlapi.com/.

1 Comment

It is not free, as far as I know

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.