PC Review


Reply
Thread Tools Rate Thread

Connect to a SQL database using console application

 
 
Claudia Fong
Guest
Posts: n/a
 
      26th Feb 2007
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

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      26th Feb 2007
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



--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"Claudia Fong" wrote:

> 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
>
> *** Sent via Developersdex http://www.developersdex.com ***
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to connect HTTP or HTTPS with the help of url in console application gujarsachin2001@gmail.com Microsoft C# .NET 1 13th Oct 2006 10:18 AM
First connection to the database (Oracle) from a .Net console application takes 6 sec Sunil Menon Microsoft ADO .NET 3 4th Sep 2006 07:15 AM
SQL Database update from C# console application =?Utf-8?B?SmFtZXM=?= Microsoft C# .NET 4 19th Aug 2005 01:10 PM
What r the requirements to connect a DB2 database to .net application =?Utf-8?B?TG9rYW5hdGg=?= Microsoft ADO .NET 0 9th Jun 2004 12:51 PM
after deploying application to different PC fails to connect to SQL database =?Utf-8?B?RGViYmll?= Microsoft ADO .NET 3 23rd Apr 2004 04:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:06 AM.