Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Peter Wagner
  
 Limeira
 
 Peter Wagner
 Tags
Subject: Problem with SQL-DMO in Connection
Thread ID: 228442 Message ID: 228442 # Views: 4 # Ratings: 0
Version: Visual FoxPro 9 Category: Databases, Tables and SQL Server
Date: Tuesday, May 19, 2009 12:40:52 AM         
   


Forget, I solved the problem.

Hi, I'm trying to make a connection to SQL Server using SQL-DMO.

The problem is how to do it passing parameters to establish the connection
This sample here works..
LOCAL cNome_banco_desejado, cSenha_conexao, cLogin
cNome_banco_desejado = ALLTRIM(Config_Conexao.Banco)
cLogin = ALLTRIM(Config_Conexao.uid)
cPassword = ALLTRIM(Config_Conexao.senha)

LOCAL oAppSQL AS SQLDMO.APPLICATION
LOCAL oServer AS SQLDMO.SQLServer
LOCAL oDatabase AS SQLDMO.DATABASE
LOCAL oNames AS SQLDMO.NameList
LOCAL oName AS Variant

oAppSQL = CREATEOBJECT("SQLDMO.Application")
oNames = oAppSQL.ListAvailableSQLServers()
FOR EACH oName IN oNames
oServer = CREATEOBJECT("SQLDmo.SqlServer")
oServer.LoginSecure = .F. && not trusted
oServer.Login = 'sa'
oserver.Password = 'zqt389pl'
oServer.CONNECT(oName)
* oServer.CONNECT(oName,'sa', 'zqt389pl') && Conect to server (this also works)

* my code here....

oServer.DisConnect
oServer = NULL
ENDFOR
oAppSQL.QUIT
oAppSQL = NULL

But when I try to establish the connection passing UserID and password to the same come I can't connect to the server?
returns error:
OLE IDispatch exception code 18456 from Microsoft SQL-DMO
(ODBC SQLState: 28000): [Microsoft][ODBC SQL Server Driver]
[SQL Server]Login failed for user ''sa''...

Any idea why?
I'm passing the same values to establish the connection...

LOCAL cNome_banco_desejado, cSenha_conexao, cLogin
cNome_banco_desejado = ALLTRIM(Config_Conexao.Banco)
cLogin = "'sa'"
cPassword = "'zqt389pl'"

LOCAL oAppSQL AS SQLDMO.APPLICATION
LOCAL oServer AS SQLDMO.SQLServer
LOCAL oDatabase AS SQLDMO.DATABASE
LOCAL oNames AS SQLDMO.NameList
LOCAL oName AS Variant

oAppSQL = CREATEOBJECT("SQLDMO.Application")
oNames = oAppSQL.ListAvailableSQLServers()
FOR EACH oName IN oNames
oServer = CREATEOBJECT("SQLDmo.SqlServer")
oServer.LoginSecure = .F. && not trusted
oServer.Login = cLogin
oserver.Password = cPassword
oServer.CONNECT(oName) && <<== Error here

* my code here....

oServer.DisConnect
oServer = NULL
ENDFOR
oAppSQL.QUIT
oAppSQL = NULL

TIA
Peter

ENTIRE THREAD

Problem with SQL-DMO in Connection Posted by Peter Wagner @ 5/19/2009 12:40:52 AM
RE: Problem with SQL-DMO in Connection Posted by Anders Altberg @ 5/19/2009 2:52:30 PM