Preliminary knowledge:
(1) The database connection string is not case-sensitive
(2) Server declaration: Data Source, Server, Address, Addr
(3) Database declaration: Initial Catalog, Database
(4) Security statement of integrated Windows account:
Integrated Security
Trusted_Connection (trusted connection)
Can be set to SSPI or True (representing true) False (representing false) The default value is false
(5) Use database account and password statement: User ID, uid Password, pwd(6) The local server can use . or localhost or (local)
//myServerAddress server address
//myDataBase database
//myUsername database username
//myPassword database password
SqlConnection
Standard connection
Data Source=myServerAddress; Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Standard connection (method 2)
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;
trusted connection
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Trusted Connection (Way 2)
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
OleDbConnection prerequisites:
Connect Access
About Microsoft.ACE.OLEDB.12.0 and Microsoft Jet OLE DB 4.0
(1) Microsoft.ACE.OLEDB.12.0
(a) Support .mdb, .accdb format
(b) Support .xls, xlsx format
(2) Microsoft Jet OLE DB 4.0 only supports .mdb format
Provider: database driver
Data Source: database source, general physical path
Standard connection
Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\mydb.mdb
Connect to Excel
HDR=YES means the header of the first row is not the data content; otherwise NO means the first row is also the data content
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;
Extended Properties="Excel 12.0 Xml;HDR=YES;IMEX=1";