Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning a Value from a UDL file

Status
Not open for further replies.

RonRepp

Technical User
Joined
Feb 25, 2005
Messages
1,031
Location
US
Hi all:

Is it possible to return a value from a UDL in code? This is what I have (written as DLL)

Code:
Public Shared Function CreateUDL(ByVal FilePathString As String) As String
        Dim SW As System.IO.StreamWriter
        Dim SR As System.IO.StreamReader
        Dim Fs As System.IO.FileStream
        Dim FileName As String
        Dim ConnectionString As String
        Dim Line As String
        Dim Proc As System.Diagnostics.Process = New System.Diagnostics.Process
        Dim SD As System.Windows.Forms.SaveFileDialog = New System.Windows.Forms.SaveFileDialog

        With SD
            .AddExtension = True
            .InitialDirectory = FilePathString 'System.Windows.Forms.Application.StartupPath & "\UDL\"
            .Filter = "Universal Data Links|*.udl"
            .Title = "Save As..."
        End With

        If SD.ShowDialog() = System.Windows.Forms.DialogResult.OK Then

            If SD.FileName <> "" Then
                FileName = SD.FileName
                If Dir(FileName) <> "" Then
                    Proc.StartInfo.FileName = FileName
                    Proc.Start()
                    Exit Function
                End If
                Fs = New System.IO.FileStream(FileName, _
                    System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None)
                Fs.Close()
                Proc.StartInfo.FileName = FileName
                Proc.Start()
            End If
        End If

        SR = New System.IO.StreamReader(FileName)
        Do
            Line = SR.ReadLine()
            If VB.Left(Line, 3) = "Pro" Then
                ConnectionString = Line
            End If
        Loop Until Line Is Nothing
        SR.Close()

        Return ConnectionString

    End Function

I'm trying to return the ConnectionString from the UDL to the parent app.

Code:
 Dim UDL As clsUDL.clsUDL = New clsUDL.clsUDL
 Dim s As String
 Dim i As Integer
  s = UDL.CreateUDL(System.Windows.Forms.Application.StartupPath & "\UDL\")
        MsgBox(s)

The DLL code works fine in the application and even as a DLL, but I cannot seem to capture the string before the UDL file is closed through the Process.

It does, however, save the UDL properly.

Any help will be greatly appreciated.





Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
If you put a breakpoint on the connection=line line, does the cursor ever get there? If not, you may want to step through that loop one line at a time and ensure that there is a line starting with "pro". You may also want to avoid case issues with something like this:

Code:
if Line.substring(0, 3).toUpper = "PRO"

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Rick:

Thanks for the input, but line always returns an empty string because it fires before the process finishes.

When I use this code in a regular app, it works fine. What I want to do is use it as a DLL for easy portability from one app to another.

Thanks,


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Rick:

The UDL requires user intervention, and I'm wondering if because I'm trying to return a string variable that is being made on the fly, if the code was not too fast. At that point I threaded it, put a sleep of 20 seconds,made sure that I was complete in opening and saving the UDL before the time period, and S still returned an empty string.

Yet, if I use the same code within the Menu Click Event, it works. I can live with this, I was just hoping someone may have run into this before.

Thanks,


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top