to set a database connection string at run time

  • Thread starter Thread starter Serge Fournier
  • Start date Start date
S

Serge Fournier

Hello,

I want to set a database connection string at run time. To do that, I want
to open the "data link property" window.
I knew how to do that in VB6 (I used the MSDASC.DataLinks object).

But with dotnet, I cannot find the good reference.

Any help will be appreciated.
Thanks
 
Hi Serge,

When you use a form, the most simple place to set it is in the load event of
the form, that works with the designer made connectionstrings as well.
(In that case do not remove the original by the designer created
connectionstring because than by changing things you are in trouble)

Something as

myconnection.connectionstring = "connectionstring"

I hope this helps?

Cor
 
Hello again, ...

I have found that link that corresponds to what I want to do :
http://www.codeguru.com/vb/gen/vb_database/article.php/c5139/

The corresponding VB code :

Imports MSDASC
Imports ADODB

Public Class Form1
Inherits System.Windows.Forms.Form

[ Windows Form Designer generated code ]

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

Dim Instance As DataLinksClass = New DataLinksClass
Dim connection As ConnectionClass = New ConnectionClass
If (Instance.PromptEdit(connection)) Then
TextBox1.Text = connection.ConnectionString
End If

End Sub
End Class

The problem is that there is an error with the 2 imports. How to set these
references ?

Thanks.
 
Back
Top