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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dataconnection string question

Status
Not open for further replies.

GaryWilsonCPA

Technical User
Jul 19, 2000
253
US
I have a dataconnection that is used throughout my program. ""\DublinFundRaising\DublinFundRaising.mdb""

I would like to allow users to have the MDB placed anywhere they want on there server. I want to build a utility to store the connection string (allowing users to edit it based on actual location)

Has anyone built something like this?

Basically I would use a textbox.text to store the data on my main menu and then access it on each form that needs the connection string.

Where should I place the string so that all forms can have access to it? What is the best way to store it?

Gary
 
high level, it would probrably be best to store the connection string in an xml file in the user's app data directory on their profile. And also build in functionality to allow them to use an open file dialog to find the file when they want to use a different copy.

As for the code behind it... well, that's the fun ;) Some places to look though, a few days ago there was a post dealing with using that [app name].config file. and while you shouldn't use that file, there is some good info in that post.

I would also point to the DataSet object's built in XML functionality, which makes dealing with XML incredibly easy!

The open file dialog, I don't know of any samples off the top of my head, but it's a pretty straight forward control.

mix it all together and you'll have a solid solution.

-Rick

----------------------
 
Well for all forms to have acccess to the string - thing string would have to be global. In a module, just declare that string as such using the following syntax:
Code:
Public strPath As Sting

Hope that helps.
 
Would the code be best placed in the main menu?

What about using access to store the string? I have done that for crystal reports with good luck.

Thanks for the tips......
 
but if you use Access to store the string...how do you then retrieve the string without making a connection to Access, but to do that, you need the connection string....arrggghhhhh!!

Sweep
...if it works dont mess with it
 
I think they may have dawned on me soon enough....thanks
 

Here is code i use to find and store a datapath to a crystal report.

OpenFileDialog1.Filter = ("Crystal Reports |*.rpt")
OpenFileDialog1.ShowDialog()
NewReport.Text = OpenFileDialog1.FileName()

I store the datapath in a textbox named newreport.text.

Is it possible to store this in a textfile and have that as part of the mainmenu?

 
Gary

Im sure you realise my post was very tongue in cheek.

I have a similar situation to yours, and although an XML file is probably the best solution, my quick and dirty solution was to just use an INI file.

Sweep
...if it works dont mess with it
 
Your post was fine, made me laugh at myself.

Is the INI file something you add to a project?

 
You certainly can do

What I do is to call a main routine in the Main Menu, that sets up defaults for all possible settings in the INI file. When you say TextBox, you obviously mean TextFile.

Im not at my development machine right now, otherwise I would post some code for handling INI files.

But instead here is a bit of code for creating a simple text file. I'll leave you to figure out the reading of the file, but you will use a StreamReader or a TextReader to do this.

Code:
Imports System
Imports System.IO

Public Class clsWriteFile

    Private Const FILE_NAME As String = "c:\MyFile.txt"
    Private sr As StreamWriter

    Public Sub zCreateFile()
        sr = File.CreateText(FILE_NAME)
    End Sub

    Public Sub zWriteLine(ByVal Contents As String, Optional ByVal Close As Boolean = False)
        sr.WriteLine(Contents)
        If Close Then sr.Close()
    End Sub

    Public Sub zCloseFile()
        sr.Close()
    End Sub

End Class





Sweep
...if it works dont mess with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top