2014-03-25 153 views
0

* 为什么只有这样才能工作?代码是不工作的,因为一些连接字符串错误可能是过时的驱动程序不确定请帮助任何建议很多好帮助是我已经尝试使用驱动程序= {Microsoft Access驱动程序( .mdb,.accdb)};仍然没有工作*vb无法连接到访问2007 db

'Connects to the Access driver and Access database in the Inetpub 
    'directory where the database is saved 
    strProvider = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:\HostingSpaces\E2ESolutions\ryan.e2e.uk.com\wwwroot\asp\guestbook.mdb;" 
    'strProvider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\HostingSpaces\E2ESolutions\ryan.e2e.uk.com\wwwroot\asp\guestbook.mdb;Persist Security Info=False;" 
    'Creates an instance of an Active Server component 
    set objConn = server.createobject("ADODB.Connection") 
    'Opens the connection to the data store 
    'objConn.Open strProvider 
    'Instantiate Command object and use ActiveConnection property to 
    'attach connection to Command object 
    response.Write("working") 
    set cm = Server.CreateObject("ADODB.Command") 
    cm.ActiveConnection = objConn 
    'Define SQL query 
    cm.CommandText ="INSERT INTO Guestbook (TB1,TB2,TB3,TB4,MB1)VALUES (?,?,?,?,?)" 
    'Define query parameter configuration information for guestbook fields 
    set objparam=cm.createparameter(, 200, , 255, strTB1) 
    cm.parameters.append objparam 
    set objparam=cm.createparameter(, 200, , 255, strTB2) 
    cm.parameters.append objparam 
    set objparam=cm.createparameter(, 200, , 255, strTB3) 
    cm.parameters.append objparam 
    set objparam=cm.createparameter(, 200, , 255, strTB4) 
    cm.parameters.append objparam 
    set objparam=cm.createparameter(, 201, , iLenMB1, strMB1) 
    cm.parameters.append objparam 
    cm.execute 
    response.write("Thank you!") 
    ELSE 
    %> 
    <h1>Guestbook</h1> 
    <!--Post information to Guestbook form --> 
    <form action="" method="POST"> 
    <p>To</p> 
    <p><input type="Text" name="To"></p> 
    <p>Email Address</p> 
    <p><input type="Text" name="EmailAdd"></p> 
    <p> CC</p> 
    <p><input type="Text" name="CC"></p> 
    <p>Subject</p> 
    <p><input type="Text" name="Subject"></p> 
    <p>Message</p> 
    <p><textarea name="Memo" rows=6 cols=70></textarea></p> 
    <input type="HIDDEN" name="Message" value="True"> 
    <input type="submit" value="Submit information"> 
    </form> 
    <% 
    End if 
    %> 
    </body> 
    </html> 
    } 
+0

我知道它与连接字符串是多少呢 –

回答

0

那么,你的连接字符串是不是很好构造。你需要引用连接字符串Click Here并尝试一些他们的。

例如

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.mdb; 
Persist Security Info=False; 

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.mdb; 
Jet OLEDB:Database Password=MyDbPassword; 

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\myAccessFile.mdb; 
Persist Security Info=False; 

ALSO - 你永远不会建立与数据库的连接。

例如

strProvider = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:\HostingSpaces\E2ESolutions\ryan.e2e.uk.com\wwwroot\asp\guestbook.mdb;" 


'What was wrong with this connection string? 
    'strProvider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\HostingSpaces\E2ESolutions\ryan.e2e.uk.com\wwwroot\asp\guestbook.mdb;Persist Security Info=False;" 


    'Creates an instance of an Active Server component 
    set objConn = server.createobject("ADODB.Connection") 


    'Uncomment here to test connection string. 
    'Opens the connection to the data store 
    objConn.Open strProvider