------------------------- Connect the access2003 string -------------------------
Provider=Microsoft.Jet.OLEDB.4.0;Data source=| Datadirectory|\data.mdb
Connecting access2010 strings
Provider=microsoft.ace.oledb.12.0;data source=| Datadirectory|\aa.accdb
-------------------------theSQL database string -------------------------------
Data source= server; Initial catalog= database name; Integra Ted Security=true; /*windows Authentication */
server= server; User id= login name; pwd= password; database= database name; /*sqlserver Authentication */
Here's an example: see the Buckle 1.
1, the first to demonstrate the connection to the SQL database:
Using System.data.sqlclient;//sqlserver Database namespace
String connstr = "Data source=localhost;initial catalog=db_aspnet; Trusted_connection=sspi; "; Establishing a Database connection channel
SqlConnection con = new SqlConnection (CONNSTR); Establishing a database Connection object
if (Con. state = = System.Data.ConnectionState.Closed)
{
Con. Open ();//Opening the database
Response.Write ("SQL Server database is turned on");
}
Label1.Text = con. State.tostring ();//For display in the UI, the same is not explained
if (Con. state = = System.Data.ConnectionState.Open)
{
Con. Close ();//Shut down the database
Response.Write ("SQL Server database is closed");
}
Label2.Text = con. State.tostring ();
2. Then connect to the Access database:
Using System.data.oledb;//access Database namespace
String connstr= "Provider=microsoft.ace.oledb.12.0;data source=| DATADIRECTORY|\\AA.ACCDB ";//Establish a database connection channel
OleDbConnection conn= New OleDbConnection (CONNSTR);//establishing a database connection object
IF (Conn. state = = System.Data.ConnectionState.Closed)
{
Conn. Open ();//Opening the database
Response.Write ("Access database is turned on");
}
Label1.Text = conn. State.tostring ();
IF (Conn. state = = System.Data.ConnectionState.Open)
{
Conn. Close ();//Shut down the database
Response.Write ("Access database is closed");
}
Label2.Text = conn. State.tostring ();
Do not like to spray, thank you!
ASP. NET connect SQL Server database and connect Access database Elite Edition