2012-02-29 135 views
0

我特林讓與SQL Server 2005數據庫連接到MS SQL Server 2005數據庫(使用使用Server.Mappath)

目前,它適用於TEST.MDB,這是在與同一個文件夾下面的應用工作應用。我如何修改MapPath以使用SQL Server。

Dim sDSN 
' To use a DSN-Less Connection use the following sDSN definition. 
' !!! By using this, UTE is able to detect Primary Keys accurately. 

sDSN = "Provider=Microsoft.Jet.OLEDB.4.0;" &_ 
    "Data Source=" & Server.MapPath("test.mdb") 

' To use a DSN (ODBC) Connection use the following sDSN defintion. 
' You need to setup an ODBC data source. 
' !!! By using this, UTE is *NOT* always able to detect Primary Keys accurately.           
' sDSN = "test" 

Dim ute 
Set ute = new clsUTE 

ute.DBName  = "TEST.MDB" ' Name of Database. For display purpose only 
'ute.ReadOnly = True  ' readonly mode 
'ute.ListTables = False  ' display toolbutton to list all tables within db 
'ute.Filters  = False  ' display toolbutton to define and activate filters 
'ute.Export  = False  ' display toolbutton to export all data to CSV file 
'ute.SQL   = False  ' display toolbutton to show current sql statement 
'ute.Definitions = False  ' display toolbutton to show field defintions 

ute.Init sDSN ' init must be called *before* any HTML code is 
       ' is written, otherwise the export feature doesn't work ! 

回答

1

你並不需要使用到使用Server.Mappath連接到一個SQLServer數據庫,不像你沒有連接到一個單獨的文件,而是SqlServer的運行實例的* .mdb文件。有關更多信息,請參閱connectionStrings.com

您的連接字符串將是這樣的:

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword; 
+0

sDSN = 「數據源= MYSERV \ PSAPP01;初始目錄= mydb的;用戶ID = exUser;密碼= exPass」 當我作出這樣一個變化不大,它會給內部服務器錯誤500 – HOY 2012-02-29 09:23:18

+0

嘗試使用連接字符串創建一個SqlConnection對象,並調用.Open(),它會告訴您連接字符串是否正常。 – Fermin 2012-02-29 09:34:10