使用表适配器时无效的连接字符串

时间:2011-01-17 18:34:03

标签: vb.net

我正在尝试将连接字符串中的变量用于表适配器。我见过的唯一干净切割方法如下,但是,我在运行时获得“无效连接字符串”。我想也许这不可能做到?

 Private Sub adaptertest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'BCPM_DDBODataSet.LTC_FBS' table. You can move, or remove it, as needed.
LTC_FBSTableAdapter.Connection.ConnectionString = "Provider=TDOLEDB;Data Source=TDDEV;Persist Security Info=True;User ID={0};Password={1};Default Database=bcpm_ddbo;Session Mode=ANSI;"
Me.LTC_FBSTableAdapter.Fill(Me.BCPM_DDBODataSet.LTC_FBS)

2 个答案:

答案 0 :(得分:1)

您似乎没有提供用户名和密码值,因此连接字符串无效。

尝试

LTC_FBSTableAdapter.Connection.ConnectionString = string.format("Provider=TDOLEDB;Data Source=TDDEV;Persist Security Info=True;User ID={0};Password={1};Default Database=bcpm_ddbo;Session Mode=ANSI;" _
,TheActualUserName _
,TheActualPassword)

答案 1 :(得分:0)

您需要修改代码以包含用户名和密码。

更新了代码段。

Private Sub adaptertest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'BCPM_DDBODataSet.LTC_FBS' table. You can move, or remove it, as needed.

Dim DBConnStr as string = "Provider=TDOLEDB;Data Source=TDDEV;Persist Security Info=True;User ID={0};Password={1};Default Database=bcpm_ddbo;Session Mode=ANSI;"

'NOTE: Replace the DBUserName and DBPwd with the actual username and pwd to DB.
DBConnStr = String.Format(DBConnStr,"DBUserName","DBPwd")

LTC_FBSTableAdapter.Connection.ConnectionString = DBConnStr 
Me.LTC_FBSTableAdapter.Fill(Me.BCPM_DDBODataSet.LTC_FBS)

有关connectionstring的更多信息,请参阅ConnectionStrings.com