標籤:
比較淩亂,有時間在整理吧。
1 Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data source=c:/D.mdb;Jet OLEDB:DataBase Password=123456!" 2 3 4 private void GetCon() 5 { 6 string strConnection="PRovider=Microsoft.Jet.OleDb.4.0;"; 7 strConnection+=@"Data Source=C:\BegaspNET\Northwind.mdb"; 8 9 OleDbConnection objConnection=new OleDbConnection(strConnection);10 11 12 objConnection.Open();13 objConnection.Close();14 15 }
以獨佔的方式開啟
檔案--資訊--加密/解密
PRovider=Microsoft.Jet.OleDb.4.0;Jet OLEDB:DataBase Password=123456789;Data Source=D:\ToWife.mdb;1.set dbconnection=Server.CREATEOBJECT("ADODB.CONNECTION")DBPath = Server.MapPath("customer.mdb")dbconnection.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPathSQL="select * from auth where id="" & user_id &"""SET uplist=dbconnection.EXECUTE(SQL)2.set dbconnection=Server.CreateObject("ADODB.Connection")DBPath = Server.MapPath("customer.mdb")dbconnection.Open "provider=microsoft.jet.oledb.4.0;data source="&dbpathSQL="select * from auth where id="" & user_id &"""SET uplist=dbconnection.EXECUTE(SQL)3.DBPath = Server.MapPath("customer.mdb")set session("rs")=Server.CreateObject("ADODB.Recordset")" rs=Server.CreateObject("ADODB.Recordset")connstr="provider=microsoft.jet.oledb.4.0;data source="&dbpathSQL="select * from auth where id="" & user_id &"""session("rs").Open sql,connstr,1,3
串連access2007
1 OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=D:/資料庫.accdb;Jet OLEDB:Database Password=123456;
串連access2003
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin";Data Source=D:/資料庫.mdb;Jet OLEDB:Database password=123456;")
建odbc源
set conn=server.createobject("Adodb.connection")conn.open "DSN=xxx;UID=;PWD=123456;Database=XXX"
破解密碼
1 public static string GetMDBPassword(string file) 2 { 3 // 未加密的MDB檔案,0x42到0x61之間的每間隔一位元組的數值 4 byte[] baseByte = { 0xbe, 0xec, 0x65, 0x9c, 0xfe, 0x28, 0x2b, 0x8a, 0x6c, 0x7b, 0xcd, 0xdf, 0x4f, 0x13, 0xf7, 0xb1, }; 5 byte flagByte = 0x0c; // 標誌 0x62 處的數值 6 string password = ""; 7 try 8 { 9 FileStream fs = File.OpenRead(file);10 fs.Seek(0x14, SeekOrigin.Begin);11 byte ver = (byte)fs.ReadByte(); // 取得access版本, 1為Access2000/2003, 0為Access9712 fs.Seek(0x42, SeekOrigin.Begin);13 byte[] bs = new byte[33];14 if (fs.Read(bs, 0, 33) != 33) return "";15 byte flag = (byte)(bs[32] ^ flagByte);16 for (int i = 0; i < 16; i++)17 {18 byte b = (byte)(baseByte[i] ^ bs[i * 2]);19 if (i % 2 == 0 && ver == 1) b ^= flag; //Access 2000/200320 if (b > 0) password += (char)b;21 }22 }23 catch { }24 25 return ( password.Equals( "" ) ? "沒有密碼!" : password );26 }
up
1 private int up(string sql) 2 { 3 int index = 0; 4 OleDbConnection con = GetCon(); 5 try 6 { 7 if (con!=null) 8 { 9 con.Open();10 OleDbCommand oc = new OleDbCommand(sql, con);11 return oc.ExecuteNonQuery();12 }13 return 0;14 }15 catch (Exception)16 {17 return 0;18 }19 }
select
1 private DataTable select(string sql) 2 { 3 DataTable dt = new DataTable(); 4 OleDbConnection con = GetCon(); 5 try 6 { 7 if (con!=null) 8 { 9 con.Open();10 //用 OleDbDataAdapter 得到一個資料集11 OleDbDataAdapter myCommand = new OleDbDataAdapter(sql,con);12 DataSet myDataSet = new DataSet();13 //把Dataset綁定books資料表14 myCommand.Fill(myDataSet);15 con.Close();16 return myDataSet.Tables[0]; 17 }18 con.Close();19 return null;20 }21 catch (Exception)22 {23 con.Close();24 return null;25 }26 }
主鍵的操作Function AddPrimaryKey()‘添加主鍵到[編號]欄位Dim strSQL As StringstrSQL = "ALTER TABLE 表1 ADD CONSTRAINT PRIMARY_KEY " _& "PRIMARY KEY (編號)"CurrentProject.Connection.Execute strSQLEnd FunctionFunction DropPrimaryKey()‘刪除主鍵Dim strSQL As StringstrSQL = "ALTER TABLE 表1 Drop CONSTRAINT PRIMARY_KEY "CurrentProject.Connection.Execute strSQLEnd Function
C#access資料庫操作