title: Minimal code to connect to MSSQL Server Express and extract some table data using Visual C++ Express
body: <p>I have the following software installed on the machine:</p>
  
  <ul>
  <li>Microsoft SQL Server Express 2005</li>
  <li>Microsoft Visual C++ Express 2008</li>
  </ul>
  
  <p>I have a .mdf file from which I need to read some data and dump to a text file. I can browse the database file using the Database Explorer in Visual Studio without any problem, but I'm having trouble connecting from the application.</p>
  
  <p>I googled far and wide, almost all "solutions" say that I should start a new project and select the "SQL server application template", which I don't have amongst templates. Other tutorials I found say I should use "Data Source Configuration Wizard", however I cannot find such wizard in any of the menus. </p>
  
  <p>I don't mind clicking although I would prefer if all this was doable in plain C++ code. Something like:</p>
  
  <pre><code>DbConnection *d = new MSSQLConnection("local", "c:\path\to\file.mdf");
  DbQuery *q = new DbQuery(d, "select * from mytable");
  ...dump the data and go home
  </code></pre>
  
  <p>Thanks.</p>
  
  <p>Alternatively, if someone can tell me how to do this in C++:</p>
  
  <p><a href="http://sharpertutorials.com/connecting-to-a-sql-server-database/" rel="nofollow">http://sharpertutorials.com/connecting-to-a-sql-server-database/</a></p>