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~
Microsoft SQL Server 2008Visual Basic Classic
Last Comment
Bob Schneider
8/22/2022 - Mon
Jim Horn
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
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
HooKooDooKu
Can you just put the SQL DB on a network drive and have everyone access the same database?
Bob Schneider
ASKER
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?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
'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_positio
str_computer_name = Space(80)
lng_buffer_size = Len(str_computer_name)
lng_ret_code = GetComputerName(str_comput
lng_null_character_positio
If lng_null_character_positio
str_computer_name = Left(str_computer_name, lng_null_character_positio
Else
str_computer_name = " "
End If