home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Reply

SQL connection string in C#

 
Thread Tools Search this Thread
Currently Active Users: 1676
Discussions: 221,040, Posts: 2,604,079, Members: 272,932
Get bargains at  »  Dealighted.com
Old May 8th, 2006, 05:25 PM     #1 (permalink)
Mobile Member
 
ShuckyD's Avatar
 
Join Date: Apr 2005
Location: S. Central PA
Posts: 3,646
SQL connection string in C#



Im working on a program that is eventually going to be deployed via wireless scanners on our companys WiFi. As i am working on getting the app built i want to make sure it links to our SQL database before i try writing much code in it. Here is the connection string that i came up with via MSDN and other various sources.

Code:
		public void ConnectToSql ()
		{
			System.Data.SqlClient.SqlConnection conn = 
				new System.Data.SqlClient.SqlConnection ();
			// TODO: Modify the connection string and include any
			// additional required properties for your database.
			conn.ConnectionString = 
				"integrated security=SSPI;data source=TEST-SQL;" +
				"user id=user;password=pass;" +
				"persist security info=False;database=TESTDB";
			try
			{
				conn.Open();
				// Insert code to process data.
				MessageBox.Show("Hello","Hello");
				
			}
			catch (SqlException ex)
			{
				MessageBox.Show(ex.Message ,ex.Number.ToString() );
			}
I was wondering if that is how i would want to pass the username and password to it, or is there another way to do so. I was reading about passing explicit credentials to a SQL server and i think this is the way it wants me to do it. Although the above code doesnt work quite right? Any suggestions or does anyone know how i should be structuring the ConnString if i am in fact doing it wrong?
__________________
Mobile: Thinkpad T61 | WinXP Pro | C2D T8300 CPU | 3GB DDR2 | 320GB Hybrid SSD HDD | AGN & WWAN
Desktop: Dell XPS 8300 | 3.4 Ghz Intel i7 | 8GB DDR3 | 1TB OS, 1.5TB Mirrored DATA
ShuckyD is offline   Reply With Quote
Old May 12th, 2006, 08:07 PM     #2 (permalink)
Banned
 
Iturea's Avatar
 
Join Date: Jan 2004
Location: Earth
Posts: 420
I don't know how your SQL Server is set up but if you can authenticate the client application with the SQL Server via Windows Authentication then this would be the ideal solution concidering you won't be exposing a username and password.

A connection string of this type would be something similiar to:

[This would work for ASP.NET C#]
conn.ConnectionString = "Data Source=YourServer;Initial Catalog=YourDB;Integrated Security=SSPI";

You show: Integrated Security=SSPI in your connection string already. Thats windows authentication. You won't need to supply a user or password with that enabled. You will just need to make sure the client can communicate with the server through windows authentication.
Iturea is offline   Reply With Quote
Old May 15th, 2006, 11:54 AM     #3 (permalink)
Mobile Member
 
ShuckyD's Avatar
 
Join Date: Apr 2005
Location: S. Central PA
Posts: 3,646
thats iturea, that string helped me and then i had to make sure i passed it a user id and password, i had to create a domain user for this program
ShuckyD is offline   Reply With Quote
Old June 2nd, 2010, 12:30 AM     #4 (permalink)
Junior Member
 
Join Date: Jun 2010
Posts: 1
HOW TO: SQL & C#

Check this link ( Shahrar Nour Khondokar - Research into embedding SQL in C# and Java ) for details on how to connect to SQL Server database from C#.NET database applications as well as Java database applications. It also describes how to pass embedded SQL queries, calling stored procedures, pass parameters etc.
SNK111 is offline   Reply With Quote
Old February 8th, 2012, 11:49 AM     #5 (permalink)
Junior Member
 
Join Date: Feb 2012
Posts: 1
C# connection string

C# connection string with sample source code

C# ADO.NET Connection String

webber
liam_web is offline   Reply With Quote
Ask a Tech Question (free)!
Most Active Discussions
This is evidence (153)
Is It Just Me? (3849)
NAS box or not? (26)
New PC gamer, can i run diablo 3??? (25)
Obama Touts Reforms After J.P. Morg.. (17)
Running Virtualbox with an AMD Proc.. (12)
Help Remove Babylon Search - Malwar.. (15)
need help with my rig (10)
Mic Playback (7)
Computer disconnects from network a.. (6)
Recent Discussions
Huawei Honor U8860 4" Android 4... (0)
bfg nvidia 7800 gtx (1)
Word, NOT saving (2)
Socket FM1 CPU "Requires discret.. (9)
XP has gone cyclic missing SXS file o.. (9)
Display Problem (5)
need help with graphics card (2)
Need help with cpu installation (8)
Help Remove Babylon Search - Malware? (15)
Running Virtualbox with an AMD Proces.. (12)
All browsers randomly crashing and BS.. (4)
Accessing computers in LAN(connected .. (2)
New PC gamer, can i run diablo 3??? (25)
New GTS 450 freezing PC (32)
my graphics card doesn't work (1)
Need new PC advice (recommendations) (0)
what card should i get (1)
VMware and BF3 (0)
GRAPHIC CARDS (1)
NAS box or not? (26)
Control 2 computers with 1 mouse and .. (6)
Radeon HD 4870 can't update, please h.. (3)
which graphic card to buy (1)
Upgrade my memory? (3)
Need help (0)

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
parsing a string in C# ShuckyD Webmastering and Programming 3 April 6th, 2009 04:23 AM
SQL Server Connection Dying out fufiter9246 Networking and Internet 3 June 19th, 2004 12:09 AM
Jave help with the (if) string Therave Webmastering and Programming 4 January 12th, 2004 11:50 AM
String together BMP joker_927 Graphic Design and Digital Photography 1 April 24th, 2003 12:29 AM
how do I detect '\n' in a string?? zskillz Webmastering and Programming 7 September 26th, 2002 07:39 PM


Currently Active Users Viewing This Thread: 5 (0 members and 5 guests)
 

All times are GMT -4. The time now is 05:48 AM.
TechIMO Copyright 2012 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28