VB6 getprivateprofle string problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: VB6 getprivateprofle string problem

  1. #1
    Join Date
    May 2014
    Posts
    1

    VB6 getprivateprofle string problem

    I was wondering what I am i doing incorrectly in the following code to retrieve a connection string from an .ini file. I keep getting a blank string.
    I have my API declared in my global mod.

    'Get DB Loaction from INI file

    Dim strDBConnect As String
    sSection$ = "DB1"
    sEntry$ = "DATABASECONN209"
    sDefault$ = ""
    sRetBuf$ = String$(256, 0) '256 null characters
    iLenBuf% = Len(sRetBuf$)
    sFileName$ = "c:\program files\conn.ini"
    '*
    X = GetPrivateProfileString(sSection$, sEntry$, _
    sDefault$, sRetBuf$, iLenBuf%, sFileName$)
    '*
    sValue$ = Left$(sRetBuf$, X)
    strDBConnect = sValue$ <<---Blank string, no return of connection string.

    ==========In my .ini file i have the following
    [DB1]
    DATABASECONN209="Provider=SQLOLEDB;Data Source=222.34.34.34;Initial Catalog=xxx;User Id=appxxx;Password=@xxxpassword"


    Thanks,
    Gene

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,835

    Re: VB6 getprivateprofle string problem

    There really is not much it could be,
    File not at the location, wrong filename
    Not able to access file
    Not finding a match to your area or section

    You could try adding a line after you set the filename something like
    Code:
    Debug.Print "Filename =: " & Dir$(sfilename)
    Which should show you the filename if it is there else DIR$() will return an empty string

    I'm not sure if the INI read routine would have an issue with spaces or tabs on the section name or not but you may want to check to make sure that there are no trailing spaces and/or tabs there, if there are that could possibly be the problem.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: VB6 getprivateprofle string problem

    Not a good idea to keep the info in an INI file. It's pure text
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center