Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Recognize PC Name in VB6

Posted on 2013-01-04
5
Medium Priority
?
284 Views
Last Modified: 2013-01-05
I have an app that was written in vb6 years ago.  I use the app on several different machines and I am wondering if there is a way that I can get it to recognize the name of the pc so I can access the sql server 2008 database regardless of which machine I am running it on (ie: "\PCName\SQLExpress".  Or better yet, get at the local db without making a machine reference at all.

Thanks~
0
Comment
Question by:Bob Schneider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 38743739
This works in Access 2010 VBA.

'Add the below API call to the general declarations section of any code module

Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

'Then add this to call the API function.  Modify the naming convention to suit your needs.

Dim str_computer_name As String, lng_buffer_size As Long, lng_ret_code As Long, lng_null_character_position As Long

str_computer_name = Space(80)
lng_buffer_size = Len(str_computer_name)

lng_ret_code = GetComputerName(str_computer_name, lng_buffer_size)

lng_null_character_position = InStr(str_computer_name, Chr(0))
If lng_null_character_position > 0 Then
    str_computer_name = Left(str_computer_name, lng_null_character_position - 1)
Else
    str_computer_name = " "
End If
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 38744659
Can you just put the SQL DB on a network drive and have everyone access the same database?
0
 

Author Comment

by:Bob Schneider
ID: 38745337
We use the software in remote locations that are not on a network.  I will look at the previous solution.  It looks like it might work.  The only way to do something like "App.Path" would be to put the db in the same directory as the compiled application, right?
0
 
LVL 9

Accepted Solution

by:
shorvath earned 2000 total points
ID: 38745871
With VB6 you could use SQL DMO
The code below will show you all the installed SQL instances of SQL Server
on the PC (regardless if the server is running or not)

It will also list the PC name as part of the servername.

'Set References to Include Microsoft SQLDMO Object Library
Dim oSQL As SQLDMO.SQLServer2
Dim oDB As SQLDMO.Database2
Dim oNames  As SQLDMO.NameList

Set oSQL = New SQLDMO.SQLServer2
Set oNames = oSQL.ListInstalledInstances

For Each oName In oNames
    Debug.Print oName
Next

Open in new window


You can the make the connection if the server exists and is online.
0
 

Author Closing Comment

by:Bob Schneider
ID: 38747083
Great!  Thanks!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question