Connect to a SQL database using console application

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top