Using System; Using System.Collections.Generic; Using System.Data; Using System.Data.Common; Using System.Linq; Using System.Text; Using System.Data.OleDb; Using System.Data.SqlClient; Using SYSTEM.DATA.SQL; Namespace ADO { public class ConnectionDemo1 { public void getoledbtable () { #region namespace Using System.Data.OleDb; #endregion #region OLE DB Access OLE DB How C # connects to access Access 2003 provider=microsoft.jet.oledb.4.0 Access 2007 provider=microsoft.ace.oledb.12.0 //(1) No database password, no user password, shared mode open //"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d: QJX document GENERICDEMODATASTUDENT.ACCDB; " //(2) has a database password, no user password, which is open exclusively //"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d: QJX document GENERICDEMODATASTUDENT.ACCDB; Jet oledb:database password=123 " //(3) There is a database password, there is a user password can use this method, but the user password even if a password must be empty, this way to open the exclusive //"Provider=Microsoft.Jet.OLEDB.4.0;Data SOURCE=D:QJX document GENERICDEMODATASTUDENT.ACCDB; Jet oledb:database password=12345; Persist security Info=true;password=;user id=admin " #endregion #region OLE DB MSSQL OLE DB C # How to connect to MSSQL Windows Authentication "Provider=sqloledb;data source=pek7-6tkx23xsqlexpress;initial catalog=test; Trusted_connection=yes; "; SQL Server Authentication "Provider=sqloledb;data source=127.0.0.1sqlexpress;initial catalog=test; User Id=sa; password=123456; "; #endregion #region OLE DB Oracle OLE DB C # ways to connect Oracle "Provider=msdaora;data Source=mydatabasealias; User Id=myuid; Password=mypassword "; #endregion String strconn = @ "Provider=microsoft.ace.oledb.12.0;data SOURCE=D:QJX document GENERICDEMODATASTUDENT.ACCDB; Jet oledb:database password=123 ";//access 2007 String strconn = @ "Provider=sqloledb;data source=127.0.0.1sqlexpress;initial catalog=test; User Id=sa; password=123456; "; OleDbConnection conn = new OleDbConnection (strconn); OleDbCommand comm = new OleDbCommand (); Comm.commandtext = "SELECT * from Users"; Comm.commandtype = CommandType.Text; Comm. Connection = conn; IF (Conn. State!= ConnectionState.Open) { Conn. Open (); DataSet ds = new DataSet (); OleDbDataAdapter da = new OleDbDataAdapter (comm); Da. Fill (DS); Conn. Close (); } } public void getsqlconnectiontable () { #region namespace Using System.Data.SqlClient; #endregion #region MSSQL SqlConnection SqlConnection C # How to connect to MSSQL Windows Authentication "Data source=pek7-6tkx23xsqlexpress;initial catalog=test; Trusted_connection=yes; "; SQL Server Authentication "Server=127.0.0.1sqlexpress;database=test; Uid=sa; password=123456 "; #endregion //string strconn = @ "server= 127.0.0.1sqlexpress;database=test; Uid=sa; password=123456 "; String strconn = @ "Data source= Pek7-6tkx23xsqlexpress;initial catalog=test; Trusted_connection=yes; "; SqlConnection conn = new SqlConnection (strconn); SqlCommand comm = new SqlCommand (); comm.commandtext = "SELECT * from Users"; comm.commandtype = CommandType.Text; Comm. Connection = conn; IF (Conn. State!=connectionstate.open) { Conn. Open (); DataSet ds = new DataSet (); SqlDataAdapter da = new SqlDataAdapter (comm); Da. Fill (DS); Conn. Close (); } } } } |