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;
Main Topics
Browse All TopicsIs 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.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
DECLARE A GLOBAL EXTERNAL FUNCTION
FUNCTION boolean GetComputerNameA(ref string cname,ref long nbuf) LIBRARY "Kernel32.dll"
AND IN YOUR SCRIPT use this
string ls_compname
long ll_buf
ll_buf = 255
ls_compname = space(ll_buf)
GetComputerNameA(ls_compna
messagebox("Computer Name", ls_compname)
and you get the computer name
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",
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(
ls_ip += String(Asc(String(BlobMid(
ls_ip += String(Asc(String(BlobMid(
ls_ip += String(Asc(String(BlobMid(
li_rc = 0
End If
MessageBox("My IP", ls_ip)
Else
li_rc = WSAGetLastError()
End If
WSACleanup()
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(SQ
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(SQ
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
To resolve the issue with SQLSA code:
Change this:
PREPARE SQLSA FROM :ls_sql;
to:
PREPARE SQLSA FROM :ls_sql USING YourTransactionObject;
Default transaction object is SQLCA, but yours may be different. If PFC then try:
PREPARE SQLSA FROM :ls_sql USING n_tr;
Also in my code above
change this:
lds_host.SetTransObject(SQ
to
lds_host.SetTransObject(n_
HTH
Business Accounts
Answer for Membership
by: shivsaPosted on 2004-01-13 at 22:55:44ID: 10111507
check this post and u will the idea. om/PB/tips /pbtip14.h tm
http://eric.aling.tripod.c