Link to home
Start Free TrialLog in
Avatar of Mateen
Mateen

asked on

host name / machine name / ip address

Is there any function in powerbuiler to find out machine name.

select host_name() in sql server enterprise manager gives machine name then why

string ls_hostname
select host_name() into :ls_hostname;
  is not being compiled in powerbuilder.

Avatar of shivsa
shivsa
Flag of United States of America image

check this post and u will the idea.
http://eric.aling.tripod.com/PB/tips/pbtip14.htm
Try this syntax:

string ls_hostname
string ls_sql
DECLARE cs_host DYNAMIC CURSOR FOR SQLSA;
ls_sql = "select host_name()"
PREPARE SQLSA FROM :ls_sql;
OPEN DYNAMIC cs_host;
FETCH cs_host INTO :ls_hostname;
CLOSE cs_host;
ASKER CERTIFIED SOLUTION
Avatar of gajender_99
gajender_99

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gajender_99
gajender_99

to get  user name

From Sybase:

GetUserNameA( )
This function returns the current users logon name. Be sure to allocate enough space for the string or you'll get a GPF when you exit PowerBuilder. There is no PowerBuilder equivalent.

Global External Function:
FUNCTION boolean GetUserNameA(ref string uname, ref ulong slength) LIBRARY "ADVAPI32.DLL"

Script:
string ls_username
string ls_var
ulong lu_val
boolean rtn
lu_val = 255
ls_username = Space( 255 )
rtn = GetUserNameA(ls_username, lu_val)
Messagebox("GetUserNameA", "Username = " + string(ls_username))
to get the ip address

create a structure
[Structure]
str_wsadata
   unsignedinteger  version
   unsignedinteger  highversion
   character  description[257]
   character  systemstatus[129]
   nsignedinteger  maxsockets
   unsignedinteger  maxupddg
   string  vendorinfo


global External function

function int WSAStartup (uint UIVerionrequested, ref str_wsadata lpWSAdata) library "wsock32.DLL"
function int WSACleanup() library "wsock32.DLL"
function int WSAGetLastError() library "wsock32.DLL"
function int gethostname(ref string name, int namelen) library "wsock32.DLL"
function string GetHost(string lpszhost,ref blob lpszaddress) library "pbws32.dll"

[script]

String ls_ip, ls_host
Blob{4} lb_host
Integer li_version, li_rc
str_wsadata lstr_wsadata

ls_host = Space(128)
li_version = 257

If WSAStartup(li_version, lstr_wsadata) = 0 Then
   If GetHostName(ls_host, Len(ls_host)) < 0 Then
      li_rc = WSAGetLastError()
   Else
      GetHost(ls_host, lb_host)
      ls_ip = String(Asc(String(BlobMid(lb_host, 1, 1)))) + "."
      ls_ip += String(Asc(String(BlobMid(lb_host, 2, 1)))) + "."
      ls_ip += String(Asc(String(BlobMid(lb_host, 3, 1)))) + "."
      ls_ip += String(Asc(String(BlobMid(lb_host, 4, 1))))
      li_rc = 0
   End If
   MessageBox("My IP", ls_ip)
Else
   li_rc = WSAGetLastError()
End If

WSACleanup()

 

Avatar of namasi_navaretnam
Gajender has covered it all. :)
Avatar of Mateen

ASKER

Hi gajender_99:

Thanks for your correct and  complete answer. 400 points is yours.

100 point will be awarded to whom who will distiguish the error in the following method

string ls_hostname
string ls_sql
DECLARE cs_host DYNAMIC CURSOR FOR SQLSA;
ls_sql = "select host_name()"
PREPARE SQLSA FROM :ls_sql;  // ERRO R
OPEN DYNAMIC cs_host;
FETCH cs_host INTO :ls_hostname;
CLOSE cs_host;

Error: Database command has not been sucessfully prepared. Back end is sql server 2000. pb is 7 build 5031.




This code works for me:

1) Create a datawindow with sql select shown below:
select host_name() as hostname

2) Save the datawindow as d_host

3) This is the code to retrieve host_name()

datastore lds_host
lds_host = create datastore

lds_host.dataobject = 'd_host'
lds_host.SetTransObject(SQLCA)
lds_host.Retrieve()
If lds_host.RowCount() > 0 Then
   ls_hostname = lds_host.GetItemString(1, 'hostname' )
   MessageBox("Debug", ls_hostname)      
Else
   MessageBox("Debug", "No Host Name")
End If      
If IsValid(lds_host) Then Destroy lds_host

Hope that helps

Namasi


Need to declare ls_hostname:

datastore lds_host
string      ls_hostname

lds_host = create datastore
lds_host.dataobject = 'd_host'
lds_host.SetTransObject(SQLCA)
lds_host.Retrieve()
If lds_host.RowCount() > 0 Then
   ls_hostname = lds_host.GetItemString(1, 'hostname' )
   MessageBox("Debug", ls_hostname)    
Else
   MessageBox("Debug", "No Host Name")
End If    
If IsValid(lds_host) Then Destroy lds_host

HTH
Mateen,
This will also work if you select from a table with onerow always. I would not recommend you do that though.

select host_name()
into :ls_hostname
from  TableWithOneRow
using sqlca;

MessageBox("debug", ls_hostname)

Thanks,

Namasi.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

select hostname from sysprocesses; --sql server 2000