Question with udl and connection string does it work? TIA Sal

S

sal

Greets, All

Question with udl and connection string does it work?

I'm having problems with the code below I keep getting an error "Keyword
not supported 'File Name'"

I was just following app.dev cbt course and for some reason it doesn't
work for me does someone know what I doing wrong

Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBrowse.Click

With OpenFileDialog1
Dim response As String
Dim strConnect As String
.Filter = "UDL connection File(*.udl)|*.udl|All Files(*.*)|*.
*"
.FilterIndex = 1
.Title = " Select a UDL File"
If .ShowDialog() = DialogResult.OK Then
txtUDLFile.Text = .FileName

SqlConnection1.ConnectionString = String.Format("File
Name={0};", txtUDLFile.Text)

SqlConnection1.Open()
If SqlConnection1.State = ConnectionState.Open Then
Console.WriteLine("Connection opened successfully")
Else
Console.WriteLine("Connection could not be
established")
End If
SqlConnection1.Close()
SqlConnection1 = Nothing

response = Console.ReadLine()

End If
End With
End Sub



Here's the udl file contents below
[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=sppDb;Data Source=(local)\vsdotnet



I'm using VS.net 2003 using vb.net


TIA
 
S

Sahil Malik

Yes the below will not work.

When specifying a udl file (which as you already know is nothing but a text
file), AND when you are using SqlConnection, the ConnectionString should be

"Integrated Security=SSPI;Persist Security Info=False;Initial
Catalog=sppDb;Data Source=(local)\vsdotnet"

i.e, start at Provider, ignore the provider key (because you are using
SqlConnection, you shouldn't specify provider), and the rest is useful.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top