vb无法连接访问2007 db

时间:2014-03-25 15:12:05

标签: vbscript ms-access-2007

* 为什么这个小工作?由于某些连接字符串错误可能是一个过时的驱动程序不确定代码不工作不确定请帮助任何建议很好帮助是的我尝试使用Driver = {Microsoft Access Driver( .mdb,。 ACCDB)};仍然没有工作*

    '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>
    }

1 个答案:

答案 0 :(得分:0)

好吧,你的连接字符串构造得不是很好。您需要引用连接字符串Click Here并尝试使用它们。

e.g。

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 - 您永远不会建立与数据库的连接。

e.g。

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