connection string of SqlConnection

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2007
Posts: 266
Reputation: quintoncoert is an unknown quantity at this point 
Solved Threads: 3
quintoncoert quintoncoert is offline Offline
Posting Whiz in Training

connection string of SqlConnection

 
0
  #1
Jul 9th, 2007
i am trying to connect to an MS Access database but i am new to C#. I have looked at, amongst others, Paladin's response to dark omen about connecting to a database and since i have connected to a database before in Visual Basic most of it makes sense to me.

However i do not understand the argument list for the connection string of the SqlConnection object's SqlConnection constructor. On various info sources the arg list for the constructor seems to differ slightly so i assume that some arguments are optional. can someone please tell me what the bare minimum of arguments are for connecting to an MS Access database on a local pc and what each argument means?
Last edited by quintoncoert; Jul 9th, 2007 at 8:29 am. Reason: ommited information
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 2
Reputation: kailash.kandpal is an unknown quantity at this point 
Solved Threads: 1
kailash.kandpal kailash.kandpal is offline Offline
Newbie Poster

Re: connection string of SqlConnection

 
0
  #2
Jul 9th, 2007
please follow following link
http://www.codeproject.com/cs/databa...ssInCSharp.asp

or write following code
  1. using System;
  2. using System.Data;
  3. using System.Data.OleDb;
  4.  
  5. public class Test{
  6. public static void Main()
  7. {
  8. string source = "Provider=Microsoft.JET.OLEDB.4.0;" + "data source=""C:\\Winnt\\Profiles\\Administrator\\Personal\\db2.mdb
  9. string command="SELECT Name, Assets FROM Bank_customer_data";
  10. OleDbCommand mCommand = new OleDbCommand();
  11. OleDbConnection mConnection=new OleDbConnection(source);
  12. mConnection.Open();
  13. mCommand.ActiveConnection=mConnection;
  14. mCommand.CommandText=command;
  15. OleDbDataReader mReader;
  16. mCommand.Execute(out mReader);
  17. // Use Read to read data line by line.
  18. while (mReader.Read())
  19. { //The data is extracted with the methods GetString and GetInt32
  20. Console.WriteLine(mReader.GetString(0) + ":" + mReader.GetInt32(1));
  21. }
  22. // Close the Reader when done.
  23. mReader.Close();
  24. // Close the connection when done.
  25. mConnection.Close();
  26. }
  27. }
  28.  
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: connection string of SqlConnection

 
0
  #3
Jul 10th, 2007
http://www.connectionstrings.com/ the best damn link hands down in finding the right string to use to connect to a given array of database types.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC