Connect to a SQL database using console application

  • Thread starter Thread starter Claudia Fong
  • Start date Start date
C

Claudia Fong

Hello

I'm trying to connect to a sql database using C# console application but
I'm having trouble to connect.. can someone help me?

// Create an empty SqlConnection object.
using (SqlConnection con = new SqlConnection())
{

// Configure the SqlConnection object's connection string.
con.ConnectionString =
"Data Source = "+ // WHAT SHOULD I PUT HERE??
"Database = LibDB;" + // the my DB
"Integrated Security=SSPI"; // integrated Windows security

// Open the Database connection.
con.Open();
}


Cheers!

Claudi
 
Try using the simplified technique:

string connectionString
="server=machineName;database=databaseName;uid=dbusername;pwd=dbpassword";

SqlConnection cn = new SqlConnection(connectionString);

Go to connectionstrings.com if you need more help.
Peter
 
Back
Top