Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to make SQLDMO work
Message
From
20/05/2009 14:12:30
Peter Wagner
Point Informática Ltda.
Limeira, Brazil
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2000
Application:
Desktop
Miscellaneous
Thread ID:
01400516
Message ID:
01401042
Views:
43
Naomi,
I had a Typo error, but below is the function...
If you improve the code, please publish it...
TIA
*************************************
* Name: IsDatabaseInServer
*************************************
* What it does: Test if the database is in the server
* More info: Simple function to check if a specific database is installed / attached to the server
* Reason: If user tries to connect to a server and the database is not attached to the server, this generates an error.
* So this function must be executed before user tries to make a connection to the server.
* Parameter: Password, UserID, Name of the database you want to find in the server
* OBS1: It checks for the database in all servers.
* OBS2: Only tested with one SQL Server, have to check with more servers
*************************************

* Sample:
* In this case the info is stored in a table, but can be stored in a .ini file or in the windows register.
cName_Database = ALLTRIM(Config_Conexao.Banco)	&& database name
cPassword = ALLTRIM(Config_Conexao.senha)		&& Password
cUserID = ALLTRIM(Config_Conexao.uid)			&& User ID

* Calls the function to test if the database is in the server
lReturn = IsDatabaseInServer(cPassword, cUserID, cName_Database)
* ... your code here


FUNCTION IsDatabaseInServer
LPARAMETERS cPassword, cUserID, cName_Database
LOCAL cPassword, cUserID, cName_Database
LOCAL oAppSQL AS SQLDMO.APPLICATION, ;
	oDatabase AS SQLDMO.DATABASE, ;
	loserver AS SQLDMO.SQLServer, ;
	oNames AS SQLDMO.NameList

oAppSQL = CREATEOBJECT("SQLDMO.Application")
oNames = oAppSQL.ListAvailableSQLServers()		&& Names of all servers

FOR EACH oName IN oNames
	loserver = CREATEOBJECT("SQLDMO.SQLServer")
	loserver.Login = cUserID
	loserver.PASSWORD = cPassword
	loserver.LoginSecure = .F.                        && SQL Server Security
	loserver.CONNECT(oName)

	nBanco = loserver.DATABASES.COUNT			&& Number of databases in the server
	DIMENSION aNomeBancos(nBanco,1)				&& array to store the names of the databases
	FOR N = 1 TO nBanco
		cNomeBanco = loserver.DATABASES(N).NAME	            && Name of the database
		STORE ALLTRIM(cNomeBanco) TO aNomeBancos (N,1)
	ENDFOR

	loserver.DisConnect
	loserver = NULL
ENDFOR

oAppSQL.QUIT
oAppSQL = NULL

* Verify in the array the name of the database
IF ASCAN(aNomeBancos,cName_Database) = 0		&& Not found
	RELEASE aNomeBancos							&& Release array
	MESSAGEBOX("The database is not in the server" + CHR(10) + CHR(13) + "Please add / install the database into the server",64,"Notification")
	RETURN .F.
ELSE
	RELEASE aNomeBancos							&& Release array
	RETURN .T.
ENDIF
>>I just solved the problem...
>>
>>TIA
>>
>
>How?
Previous
Reply
Map
View

Click here to load this message in the networking platform