473,749 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ConnectionS tring =
"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 25631
Try using the simplified technique:

string connectionStrin g
="server=machin eName;database= databaseName;ui d=dbusername;pw d=dbpassword";

SqlConnection cn = new SqlConnection(c onnectionString );

Go to connectionstrin gs.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.ConnectionS tring =
"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
2783
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 windows by themselves, and force them to use the Main app. If I use Windows Services, I'm not sure can I create one dynamically, and then kill easily. But, if using console application, my following coding is working now. using System;
3
5870
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 ? Thanks.
2
1559
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 application to be run as hidden. Any idea how to do this? Thanks, -- Thanks, Mahesh
4
5118
by: vee10 | last post by:
hi, I need help to connect to database(SQLSERVER2005) using javascript please help me
0
2707
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 ,example sin graph in window form but i must give the commands in console application ?
5
2082
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 code below, it didn't update the record.. Can someone tell me? Cheers
3
2911
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 on the java.library.path: C:\Program Files\Java\jdk1.5.0_12\bin;.;C:\WINDOWS\System32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin;C:\Program...
0
1086
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 Application is crash! without any chance exception being handled. The application shut down it self! Any way to trace this problems??
2
3727
by: kyara | last post by:
Please I need written code to use message box with console application
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9388
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.