Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

connect vb6 to database

2 views
Skip to first unread message

F.N.Z

unread,
May 21, 2008, 2:50:00 PM5/21/08
to
I have a program in vb6 that connects to a database in SQL. I don't have any
problem with connecting my forms to database, but I have problem when I want
to bring my program to another computer. when I change the computer, even
when I make it exe, I faced a problem, because the system's name has been
changed .I have to change all connection strings in my program. I have been
make a backup from my database in SQL in main computer, and then restore the
database in the destination computer, but the system name made the problem.
Is there any solution that the program make the changes by itself, or can I
have any setup programs that make the changes itself?

Richard Mueller [MVP]

unread,
May 21, 2008, 3:24:05 PM5/21/08
to

"F.N.Z" <F...@discussions.microsoft.com> wrote in message
news:6A539A0F-F4DC-450F...@microsoft.com...

A lot depends on your circumstances and who uses the program. I have a
program that reads the SQL Server name from the local registry. I have a
utility the customer runs that prompts for the server, verifies that it can
connect, then writes the server name to the local registry. Other options
are to have the app prompt for the server or read it from a text file.
Assuming the database and instance names never change, your program needs
some way to determine the name of the SQL Server without you rebuilding the
exe.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


expvb

unread,
May 21, 2008, 3:24:51 PM5/21/08
to
"F.N.Z" <F...@discussions.microsoft.com> wrote in message
news:6A539A0F-F4DC-450F...@microsoft.com...

Save the connection string, or the computer or file name to an INI file, and
use that. Add an option in your program and call it "Database Setup", etc.
Search the newsgroups fro "vb GetPrivateProfileString" for samples.


Jeff Johnson

unread,
May 21, 2008, 3:49:14 PM5/21/08
to
"F.N.Z" <F...@discussions.microsoft.com> wrote in message
news:6A539A0F-F4DC-450F...@microsoft.com...

>I have a program in vb6 that connects to a database in SQL. I don't have

Maybe I'm missing something, but couldn't this be solved by using "(local)"
as the server name in the connection string instead of an explicit computer
name? (Of course, this won't work if you're accessing a named instance of
SQL Server.)


F.N.Z

unread,
May 22, 2008, 2:03:00 AM5/22/08
to

"Richard Mueller [MVP]" wrote:

Thank you for answering my question. I'm not very professional in system
registry, so I don't know how I can find the server name from the local
registry. can you help me about that?

Richard Mueller [MVP]

unread,
May 22, 2008, 8:15:26 AM5/22/08
to

"F.N.Z" <F...@discussions.microsoft.com> wrote in message
news:AD8BAA68-A6B1-48E0...@microsoft.com...

I wrote a utility that writes the name of the server to the registry. The
server name is not otherwise in the registry. I needed a place to save this
information and the only choices are the registry and a text file (like a
*.ini file). I used HKLM\Software\MyCompany\MyApp\Server, where "MyCompany"
is the name of my company and "MyApp" is the name of my application. My
application reads the name of the server when it starts.

When my application is installed the setup program runs my utility at the
end. This prompts the user for the name of the SQL server, verifies that it
can connect, then writes the name to HKLM\Software\MyCompany\MyApp\Server.
The customer must run the utility again if they move the SQL Server database
to another computer. I have seen several other applications that use a text
file to save the server name (and sometimes other information).

Two methods I know of to read and write values to the registry. One is to
use the StdRegProv class of WMI. See this link:

http://www.microsoft.com/technet/scriptcenter/guide/sas_reg_utys.mspx

Another is to use the RegRead and Regwrite methods of the wshShell object.

http://msdn.microsoft.com/en-us/library/x05fawxd.aspx

expvb

unread,
May 22, 2008, 1:10:19 PM5/22/08
to
"Richard Mueller [MVP]" <rlmuelle...@ameritech.nospam.net> wrote in
message news:%23ZVNHWA...@TK2MSFTNGP04.phx.gbl...

> *.ini file). I used HKLM\Software\MyCompany\MyApp\Server, where
> "MyCompany" is the name of my company and "MyApp" is the name of my
> application. My application reads the name of the server when it starts.

Since Windows 2000, only Power Users and higher have write access to HKLM
and "Program Files", so use HKCU, "Application Data", or All Users
"Documents" folder. For writing to HKCU, you can use the built-in
GetSetting/SaveSetting functions, which saves to the following key:

HKEY_CURRENT_USER\Software\VB and VBA Program Settings\<appname>\<section>

Here are some locations that you can save your data to, and the restrictions
on them:

1 - HKCU: Can be read/written to by the current user, but you can't see
other users settings. Use this for small per user settings.

2 - Per User "Application Data" can be read/written to using the current
user. Put any small Per User INI or files here.

3 - Per User "Local Settings\Application Data" can be read/written to using
the current user. Put any large Per User INI or files here. The files in
this folder do not roam with the user. When a roaming user logs in or out,
HKCU and the user's profile are downloaded or uploaded to a server, except
the files and folders under "Local Settings\Application Data", to save
bandwidth, and reduce the time for logon/logout. For instance, IE saves the
Temporary Internet Files there so they are not uploaded/downloaded. Roaming
users see their settings and desktop the same way regardless of which
computer they login at.

4 - All Users "Application Data": Put any INI or files that are supposed to
be shared among all users here. This folder is not truly shared read/write
by default, you have to adjust the permissions at install time so any user
can read or write to it. If you are using Inno Setup, this can be done by 2
simple lines:

[Dirs]
Name: "{commonappdata}\Company\Software"; Permissions: users-full

By default, in 2000 and XP, files created by Admins or Power Users cannot be
written to by the limited "Users" group, so it's necessary to adjust the
permissions like the above. Microsoft says and does adjust the permissions
for their applications. To adjust the permissions using PDW, you have to
modify it and add code to do it, see MSKB Q240176 for sample code.

5 - Per User "My Documents" folder can be read/written to by an user. Use a
subfolder with your software name to save files that the user is expected to
open later, like graphics files created by your application.

6 - All Users "Documents" folder can be read/written to by an user by
default. This is displayed as "Shared Documents" in Windows Explorer(At the
bottom of the folder list). I think this is the Public folder in Vista.

Use SHGetSpecialFolderLocation() to get the locations above, don't hardcode
them. Search the newsgroup for "vb SHGetSpecialFolderLocation" for samples.
Here is a link for where the above is explained:

http://msdn.microsoft.com/en-us/library/ms995853.aspx

F.N.Z

unread,
May 24, 2008, 1:22:00 AM5/24/08
to

"expvb" wrote:

thank you very much.

F.N.Z

unread,
May 24, 2008, 1:22:00 AM5/24/08
to

"Richard Mueller [MVP]" wrote:

thank you very much.

0 new messages