Skip to content

Instantly share code, notes, and snippets.

@mpfund
Created September 9, 2013 13:17
Show Gist options
  • Save mpfund/6495469 to your computer and use it in GitHub Desktop.
Save mpfund/6495469 to your computer and use it in GitHub Desktop.
Simple connection to SQL-Server (localDB)
class Program
{
static void Main(string[] args)
{
string connstr = "Data Source=(localDB)\\v11.0;Initial Catalog=inloox;Integrated Security=true";
SqlConnection conn = new SqlConnection(connstr);
try
{
conn.Open();
var comm = conn.CreateCommand();
comm.CommandText = "Select * from Configuration";
var myreader = comm.ExecuteReader();
while(myreader.Read())
{
Console.WriteLine(myreader[0].ToString());
Console.WriteLine(myreader[1].ToString());
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
conn.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment