# Re: 我已经试到!谢谢!怎样动态设定DataEnvironment 的DataSource?

Posted by Fai on August 12, 1999 at 12:21:33:

In Reply to: Re: 怎样动态设定DataEnvironment 的DataSource? posted by 大汉堡 on August 12, 1999 at 04:38:38:

: : : : 本人有一个DataEnvironment,DataSource="D:\ESU\ESU.mdb",DataEnvironment 裹面有几个Command
: : : : 由于这程式会设在不同的电脑上,因此需要改变不同的Path
: : : : 所以要动态设定DataEnvironment 的DataSource

: : : : 我在form中,写了此行
: : : : ConnStr = "Provider=Microsoft.Jet.OLEDB.3.51;" & "Data Source=" & DbDir & "ESU.mdb"
: : : : DataEnvironment1.Connection1.ConnectionString = ConnStr
: : : : 想动态改变Directory Path 的位置,当一用到Command 的时候
: : : : Error Message is displayed as "[Microsoft][ODBC Driver Manager] Data Source name not found and no default driver specified"
: : : : 请问应怎么办?
: : : 不要先设定,于程式执行再做
: : : Private Sub Connection1_WillConnect(ConnectionString As String, Userid As String, Password As String, Options As Long, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
: : : DataEnvironment1.Connection1.Properties("data source") = ConnStr
: : : End Sub

: : 首先感谢您的回应,我在DataEnvironment1的Connection1中加入这行,DbDir是DataBase的
: : Directory: DbDir="D:\Fai\ESU\"
: : Private Sub Connection1_WillConnect(ConnectionString As String, Userid As String, Password As String, Options As Long, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
: : ConnStr = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & DbDir & "ESU.mdb"
: : DataEnvironment1.Connection1.Properties("Data Source") = ConnStr
: : End Sub
: : 但是,却出了这Error:[Microsoft][ODBC Driver Manager]Data Source name too long
: : 请问我应怎么办?谢谢

: 你的ConnStr仅需 Path and DataBaseName,
: ConnStr = "d:\Fai\ESU\ESU.mdb"
: 而Provider可直接于DataEnvironment的属性页内设定

Follow Ups: