Results 1 to 14 of 14

Thread: Set Database Location

  1. #1

    Thread Starter
    Addicted Member girl81's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    211

    Set Database Location

    Hi all i have question.I use Access and CR 8.5.
    I have produced many reports.. i used a data environment to retrieve a database.I fixed the location in partition C.I never think to try to put my system in other partition before this..can someone tell me the way where should i retrieve a Database so that its flexible to run anywhere..

    Thanks in advance

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Set Database Location

    I normally use ADODB commands only for all DB work. I allow the user to install the app and DB where ever the wish. I then use the registry to store the database location and on app startup I retrieve that registry setting into a global variable that I use whe I call to open database and pass that location to CR to set the location of all tables in the report.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Addicted Member girl81's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    211

    Re: Set Database Location

    Quote Originally Posted by GaryMazzone
    I normally use ADODB commands only for all DB work. I allow the user to install the app and DB where ever the wish. I then use the registry to store the database location and on app startup I retrieve that registry setting into a global variable that I use whe I call to open database and pass that location to CR to set the location of all tables in the report.
    Thanks a lot...but can u tell me more details how to do that..

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Set Database Location

    Are you using VB to connect to the database? or is this all Access?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Addicted Member girl81's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    211

    Re: Set Database Location

    Quote Originally Posted by GaryMazzone
    Are you using VB to connect to the database? or is this all Access?
    Im using a vb6

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Set Database Location

    This is how I do this:

    gstrLoc and gDBName are global variables that are declared in a module

    This runs from Sub Main:
    VB Code:
    1. 'Get the DBData
    2. gstrLoc = GetSetting(App.Title, "Settings", "DBPath")
    3. gDBName = GetSetting(App.Title, "Settings", "DBName")

    This is a sub called Open_DB that is called from Sub Main (gDBConn is a global var that is defined as and ADODB.Connection):
    VB Code:
    1. Public Sub Open_DB()
    2. Dim FSys As FileSystemObject
    3. Dim intDot As Integer
    4.  
    5. On Error GoTo DBOpenError
    6. Set FSys = New FileSystemObject
    7. If gDBName <> "" And FSys.FileExists(gstrLoc & "\" & gDBName) Then
    8.     Set gDBConn = New ADODB.Connection
    9.     If Not gDBConn.State Then
    10.         With gDBConn
    11.             .Provider = "Microsoft.Jet.Oledb.4.0"
    12.             .Properties("Jet OLEDB:System Database") = gstrLoc & "\RSM.mdw"
    13.             .Properties("Password") = "Sam23!BigFoot"
    14.             .Properties("User ID") = "RSMAdmin"
    15.             .ConnectionString = gstrLoc & "\" & gDBName
    16.             .Open
    17.         End With
    18.     End If
    19. Else
    20.     gstrLoc = ""
    21.     gDBName = ""
    22.     frmOptions.Show
    23.     frmOptions.cmdBrowse.Value = True
    24. End If
    25. intDot = InStr(1, gDBName, ".")
    26. fMainForm.Caption = "Radiation Safety Manager - " & Left(gDBName, intDot - 1)
    27. Exit Sub
    28. DBOpenError:
    29.     gstrLoc = ""
    30.     gDBName = ""
    31.     frmOptions.Show
    32.     frmOptions.cmdBrowse.Value = True
    33.    
    34. End Sub

    When the app closes I write the DB data back to the registry (incase the user chages the DB Name or Location). This is when the main form closes (unloads)
    VB Code:
    1. SaveSetting App.Title, "Settings", "DBName", gDBName
    2.         SaveSetting App.Title, "Settings", "DBPath", gstrLoc

    For the CR I have a sub that set the DB Name and Location:
    VB Code:
    1. Public Sub Set_Crystal_Datatables(ByVal intNum As Integer)
    2. Dim i As Integer
    3.  
    4. For i = 0 To intNum
    5.     fMainForm.crRep.DataFiles(i) = gstrLoc & "\" & gDBName
    6. Next i
    7.  
    8. End Sub
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7

    Thread Starter
    Addicted Member girl81's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    211

    Re: Set Database Location

    Thanks a lot..but its look very complicated..im not expert..very difficult for me to understand...

    ok let me try it out first then i will tell u..Thanks a lot

  8. #8

    Thread Starter
    Addicted Member girl81's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    211

    Re: Set Database Location

    Crystal Report

  9. #9
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Set Database Location

    if you want to install the database into the default directory where your app is installed in other systems, then you can use App.Path to get your application's installation path. and you can refer your database path with this, suppose, you have installed in D:\SomeDir\SomeSubDir then your App.Path will return this, You can use in your project App.Path & "\YourDatabaseFile.Mdb"
    And for Crystal if you design the report with a dsn name then in your app you can create the dsn whenever the app is loaded.

    To create DSN add these lines into your projects loading code...
    VB Code:
    1. 'Setting the Database to the DSN for Crystal Report use
    2.     Dim strAttribs As String
    3.     strAttribs = "Description=Your ODBC Driver Description" & Chr$(13) & "DBQ=" & DBName
    4.     rdoEngine.rdoRegisterDataSource "YourDSNName", "Microsoft Access Driver (*.Mdb)", True, strAttribs
    Last edited by ganeshmoorthy; Aug 25th, 2006 at 12:30 PM.
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  10. #10

    Thread Starter
    Addicted Member girl81's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    211

    Re: Set Database Location

    Quote Originally Posted by ganeshmoorthy
    for Crystal if you design the report with a dsn name then in your app you can create the dsn whenever the app is loaded.
    can u tell me details how to create the dsn

  11. #11
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Set Database Location

    i edited my previous post with the create dsn code
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  12. #12
    Addicted Member mabbas110's Avatar
    Join Date
    Oct 2005
    Location
    Karachi , Pakistan
    Posts
    172

    Re: Set Database Location

    The only suitable solution according to ur answer is that u create DSN and call all the database tables trough that dsn in reports.

    It will be helpful as when u change the database location or put it on network then u have nothing do by ur self , the report will update its database location itself.
    Thanks and Regards,

    Muhammad Abbas

  13. #13
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Set Database Location

    Automatically setting DSN in ODBC
    for more detail to create run time dsn you can clink on the above link and check the post 2

  14. #14
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Set Database Location

    It's quite simple to change the database location in a Crystal Report, see this post... http://www.vbforums.com/showthread.php?t=423542
    If you're using the Crystal OCX it's just as easy...
    VB Code:
    1. Report.DataFiles(0) = "path & name of your database"
    I've never needed to use a DSN. In my opinion they're cumbersome.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width