Created
September 9, 2013 13:17
-
-
Save mpfund/6495469 to your computer and use it in GitHub Desktop.
Simple connection to SQL-Server (localDB)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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