473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Connect to a SQL database using console application

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 ***
Feb 26 '07 #1
1 25593
Try using the simplified technique:

string connectionString
="server=machineName;database=databaseName;uid=dbu sername;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 ***
Feb 26 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mullin Yu | last post by:
But, I want is that I can have a Main app that will start a new process or kill one particular or all process. The process will open a console exe. But, I don't want the user to close the console...
3
by: yaron | last post by:
Hi, 1. How to use SSL to connect 2 c# console application clients ? 2. Ineroperability with Java : How to use SSL to connect C# console application client and JAVA console application client...
2
by: Mahesh Nimbalkar | last post by:
For a few reasons I can not use windows services in my application to be run as scheduled job So I am using console application which will be executed by windows scheduler. I want this console...
4
by: vee10 | last post by:
hi, I need help to connect to database(SQLSERVER2005) using javascript please help me
0
by: suedasszyy | last post by:
Haiiii.... i'm new for VB.net. can someone help me to solve those question? is it possible to draw a graph such as Sin graph using console application? if not, how can i draw a graph...
5
by: Claudia Fong | last post by:
Hi, I'm using console application to connect to a db and I managed to use the SELECT statement to display records in my DB but I also need to UPDATE some fields in my table but after I run the...
3
by: arasub | last post by:
ep 20, 2007 11:25:57 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found...
0
by: edwardsurjadi | last post by:
guys, i have ASP.NET website(UI) that connect to BusinessLogic(Console Application hosting the BL) through .NET Remoting on different computer. What amussing is, sometimes (very rare), the BL...
2
by: kyara | last post by:
Please I need written code to use message box with console application
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.