List all databases on server in OLE

Discussion forum about all things SqlBase.
base_user

List all databases on server in OLE

Post by base_user » 02 Dec 2016, 16:33

Is there a way to get the list of active SqlBase databases on a server using the OLE interface? If not is there anyway to get this information into a .Net program?
Last edited by base_user on 05 Dec 2016, 21:26, edited 1 time in total.

Mike Vandine

Re: List all databases on server in OLE

Post by Mike Vandine » 05 Dec 2016, 05:26

Hi,

Are you looking to get a list of databases that are installed or ones that currently have users connected?

Have a look at the SQLBase API guide:

sqldbn - DataBase Names

Syntax

#include "sqlbase.h"
SQLTAPI sqldbn (serverid, buffer, length)
SQLTDAP serverid; /* Server identifier */
SQLTDAP buffer; /* Directory list */
SQLTDAL length; /* Buffer length */

Description

This function returns a list of the databases on the specified server.
Use this function instead of sqldir.

Parameters

serverid

A pointer to a null-terminated string that contains the name of the server specified in sql.ini. Specify a null server name to get a directory of local databases.
buffer
A pointer to the variable where this function returns the database names. Each name is null-terminated. The end of the list is marked by an extra null-
terminator. For example, the database names demo, payables, and emp are returned in this format:
demo\0payables\0emp\0\0

length

The length of the area pointed to by buffer.

Return value

If this function returns zero, it was successful. If this function returns a non-zero value, it was unsuccessful.

Example

main()
{
srvname="SERVER1";
/* DIRECTORY OF DATABASES */
if (rcd = sqldbn(srvname,buffer,len))
apierr("SQLDBN");
else
{
j = 0;
printf("Directory of Databases : ");
while ( (buffer[j] != '\n') && (j< 20) )
{
if (buffer[j] == '\0')
{
printf(", ");
}
169
else
{
printf("%c",buffer[j]);
}
j++;
}
printf("\n");
}
}

Sorry that the code doesn't seem to be aligned correctly. It is in the manual.

Hope this helps.

base_user

Re: List all databases on server in OLE

Post by base_user » 05 Dec 2016, 21:26

Thanks but I was looking for an OLE or .Net solution. Coding in C might be an option, but it is not a good option for me.

Mike Vandine

Re: List all databases on server in OLE

Post by Mike Vandine » 06 Dec 2016, 02:32

Hopefully someone else will jump in with a solution.

Best regards,

krs

Re: List all databases on server in OLE

Post by krs » 07 Dec 2016, 11:25

Hi all,
here is particular C# solution:
On Form add comboBox, connectionstring, command, commandextension, on form load it will populate combobox with names of active databases on server.


public SQLBaseCommand command = new SQLBaseCommand();

public SQLBaseCommandExtensions sbe = new SQLBaseCommandExtensions(command);

List<string> Getdatabases(string server)
{
SQLBaseCommandExtensions sbe = new SQLBaseCommandExtensions(command);
List<string> databases = sbe.SqlGetDatabasesForServer(server);
return databases;
}

private void Form_Load(object sender, EventArgs e)
{
// Add ComboBox on form cbDatabases
cbDatabases.SelectedIndex = -1;
cbDatabases.Items.Clear();
List<string> Databases = GetDatabases("Yours server Name eg. SERVER1");
cbDatabases.Items.AddRange(Databases.ToArray());
}


Br,

base_user

Re: List all databases on server in OLE

Post by base_user » 12 Jan 2017, 18:32

Thanks, that is definitely what I am looking for! I found the DLL for the SqlBaseCommand, Gupta.SQLBase.Data.dll, but where is the DLL for SQLBaseCommandExtensions???

Thanks again for your reply.

base_user

Re: List all databases on server in OLE

Post by base_user » 12 Jan 2017, 21:03

Found it, the 11.5 client drivers did not contain this but the 12.0 drivers do. Added the 12.0 Gupta.SQLBase.Data to my visual Studio project and the SqlBaseComandExtensions is now available. Not exactly an OLE solution but close enough, not sure an OLE solution could be done since OLE implies a connection to a database, this request was for something that did not require a database connection.

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 1 guest