开发者

Invalid connection string when using table adapter

开发者 https://www.devze.com 2023-02-04 23:18 出处:网络
I\'m trying to use variables in my connection string to a table adapter. The only clean cut method I\'ve seen is the following, however, I\'m getting \"Invalid Connection string\" upon run-time. I\'m

I'm trying to use variables in my connection string to a table adapter. The only clean cut method I've seen is the following, however, I'm getting "Invalid Connection string" upon run-time. I'm assuming maybe this can't be done?

 Private Sub adaptertest_Load(ByVal sender As System.Object, ByV开发者_如何学Cal 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)


You don't appear to be providing the user name and password values, hence invalid connection string.

Try

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)


You need modify your code to contain the username and password.

Updated code snippet.

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)

For more information on connectionstring, refer ConnectionStrings.com

0

精彩评论

暂无评论...
验证码 换一张
取 消