dbTalk Databases Forums  

How to connect to Network database server ?

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss How to connect to Network database server ? in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
V Jain
 
Posts: n/a

Default How to connect to Network database server ? - 10-17-2007 , 02:34 PM






Hi,
I am trying to connect to a network database server in my
embedded SQL code using a DSN. Just before I do the CONNECT
statement, I try to find the network database server using
db_find_engine(&sqlca, theBnk), where "theBnk" is network
database server name. For some reasons, this function is
failing with SQLCODE -100. And this function is successful
if database server is runing on local machine. Also, I can
connect to this network database server using ODBC
Administrator with the same DSN. Could anybody help me why
db_find_engine() function is failing for a network database
server ? Below is my code that illustrates this:

if ( db_init(&sqlca) != 0 )
{
// Locate the engine.
if ( db_find_engine(&sqlca, theBnk) )
{
// Engine located, connect to it.
EXEC SQL CONNECT USING 'DSN=test';

if ( SQLCODE == SQLE_NOERROR )
{
HaveDBConnection = TRUE;
}
else
{
printf("Unable to establish connection to
database.
SQLCODE = [%d]\n", SQLCODE);
}
}
else
{
printf("Unable to find database engine. SQLCODE =
[%d]\n", SQLCODE);
}
}
else
{
printf("Unable to initialize database. SQLCODE =
[%d]\n",
SQLCODE);
}

Thanks,
V Jain

Reply With Quote
  #2  
Old   
Graeme Perrow
 
Posts: n/a

Default Re: How to connect to Network database server ? - 10-17-2007 , 02:46 PM






V Jain wrote:
Quote:
Hi,
I am trying to connect to a network database server in my
embedded SQL code using a DSN. Just before I do the CONNECT
statement, I try to find the network database server using
db_find_engine(&sqlca, theBnk), where "theBnk" is network
database server name. For some reasons, this function is
failing with SQLCODE -100. And this function is successful
if database server is runing on local machine. Also, I can
connect to this network database server using ODBC
Administrator with the same DSN. Could anybody help me why
db_find_engine() function is failing for a network database
server ? Below is my code that illustrates this:
Can you show us the contents of the DSN? Run:

dbdsn -g test

--

Graeme Perrow
Senior Software Developer
gperrow _at_ ianywhere _dot_ com
iAnywhere Solutions Inc.
A Sybase company

Whitepapers, TechDocs, bug fixes are all available through the iAnywhere
Developer Community at http://www.ianywhere.com/developer/


Reply With Quote
  #3  
Old   
Kory Hodgson
 
Posts: n/a

Default Re: How to connect to Network database server ? - 10-17-2007 , 03:02 PM



Assuming you have adjusted to add in the host name and port in the DSN
and there is no firewall blocking this connection. I would make sure the
Network Server is already started. As when you try to make this
connection locally it can start up an engine, but when connecting to
another system the Network Database Server must already be running.

--
Kory Hodgson
Sybase iAnywhere



V Jain wrote:
Quote:
Hi,
I am trying to connect to a network database server in my
embedded SQL code using a DSN. Just before I do the CONNECT
statement, I try to find the network database server using
db_find_engine(&sqlca, theBnk), where "theBnk" is network
database server name. For some reasons, this function is
failing with SQLCODE -100. And this function is successful
if database server is runing on local machine. Also, I can
connect to this network database server using ODBC
Administrator with the same DSN. Could anybody help me why
db_find_engine() function is failing for a network database
server ? Below is my code that illustrates this:

if ( db_init(&sqlca) != 0 )
{
// Locate the engine.
if ( db_find_engine(&sqlca, theBnk) )
{
// Engine located, connect to it.
EXEC SQL CONNECT USING 'DSN=test';

if ( SQLCODE == SQLE_NOERROR )
{
HaveDBConnection = TRUE;
}
else
{
printf("Unable to establish connection to
database.
SQLCODE = [%d]\n", SQLCODE);
}
}
else
{
printf("Unable to find database engine. SQLCODE =
[%d]\n", SQLCODE);
}
}
else
{
printf("Unable to initialize database. SQLCODE =
[%d]\n",
SQLCODE);
}

Thanks,
V Jain

Reply With Quote
  #4  
Old   
Ian McHardy
 
Posts: n/a

Default Re: How to connect to Network database server ? - 10-18-2007 , 10:05 AM



db_find_engine is designed to find a local server with the given name using
shared memory. You could use db_string_ping_server if you want to use a
connection string to determine if you can connect to a server (without doing
the connection to the database).

I recommend not calling db_find_engine unless it is only for a local server.
In your case, you can skip the db_find_engine or db_string_ping_server, and
just attempt the database connection first. If the connection fails, the
error will indicate if the server was found or not.

--

Ian McHardy (iAnywhere Solutions)

Please reply only to the newsgroup.

Whitepapers, TechDocs, bug fixes are all available through the iAnywhere
Developer Community at http://www.ianywhere.com/developer

<V Jain> wrote

Quote:
Hi,
I am trying to connect to a network database server in my
embedded SQL code using a DSN. Just before I do the CONNECT
statement, I try to find the network database server using
db_find_engine(&sqlca, theBnk), where "theBnk" is network
database server name. For some reasons, this function is
failing with SQLCODE -100. And this function is successful
if database server is runing on local machine. Also, I can
connect to this network database server using ODBC
Administrator with the same DSN. Could anybody help me why
db_find_engine() function is failing for a network database
server ? Below is my code that illustrates this:

if ( db_init(&sqlca) != 0 )
{
// Locate the engine.
if ( db_find_engine(&sqlca, theBnk) )
{
// Engine located, connect to it.
EXEC SQL CONNECT USING 'DSN=test';

if ( SQLCODE == SQLE_NOERROR )
{
HaveDBConnection = TRUE;
}
else
{
printf("Unable to establish connection to
database.
SQLCODE = [%d]\n", SQLCODE);
}
}
else
{
printf("Unable to find database engine. SQLCODE =
[%d]\n", SQLCODE);
}
}
else
{
printf("Unable to initialize database. SQLCODE =
[%d]\n",
SQLCODE);
}

Thanks,
V Jain



Reply With Quote
  #5  
Old   
V Jain
 
Posts: n/a

Default Re: How to connect to Network database server ? - 10-22-2007 , 12:12 PM



Thanks a lot Sir. I tried db_string_connect() to connect to
network server and it worked just fine. Now I can connect
to netwrok server using a DSN in my conenction string. I
can't thank you enough for this tip.

Regards,
VJ

Quote:
db_find_engine is designed to find a local server with the
given name using shared memory. You could use
db_string_ping_server if you want to use a connection
string to determine if you can connect to a server
(without doing the connection to the database).

I recommend not calling db_find_engine unless it is only
for a local server. In your case, you can skip the
db_find_engine or db_string_ping_server, and just attempt
the database connection first. If the connection fails,
the error will indicate if the server was found or not.

--

Ian McHardy (iAnywhere Solutions)

Please reply only to the newsgroup.

Whitepapers, TechDocs, bug fixes are all available through
the iAnywhere Developer Community at
http://www.ianywhere.com/developer

V Jain> wrote in message
news:471663d9.75cc.1681692777 (AT) sybase (DOT) com... Hi,
I am trying to connect to a network database server in
my embedded SQL code using a DSN. Just before I do the
CONNECT statement, I try to find the network database
server using db_find_engine(&sqlca, theBnk), where
"theBnk" is network database server name. For some
reasons, this function is failing with SQLCODE -100.
And this function is successful if database server is
runing on local machine. Also, I can connect to this
network database server using ODBC Administrator with
the same DSN. Could anybody help me why db_find_engine()
function is failing for a network database server ?
Below is my code that illustrates this:
if ( db_init(&sqlca) != 0 )
{
// Locate the engine.
if ( db_find_engine(&sqlca, theBnk) )
{
// Engine located, connect to it.
EXEC SQL CONNECT USING 'DSN=test';

if ( SQLCODE == SQLE_NOERROR )
{
HaveDBConnection = TRUE;
}
else
{
printf("Unable to establish connection to
database.
SQLCODE = [%d]\n", SQLCODE);
}
}
else
{
printf("Unable to find database engine. SQLCODE
= [%d]\n", SQLCODE);
}
}
else
{
printf("Unable to initialize database. SQLCODE =
[%d]\n",
SQLCODE);
}

Thanks,
V Jain



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.