Page 1 of 1
Acceder a MSSQL
Posted: Mon Dec 09, 2013 4:42 pm
by Willi Quintana
Amigos, algún código lib o dll para acceder a MSSQL y poder leer datos y actualizaciones??, probe los demos pero no van,,,,
Salu2
Willi
Re: Acceder a MSSQL
Posted: Mon Dec 09, 2013 8:51 pm
by Rick Lipkin
Willi
Connecting to Ms Sql server is no different than any other RDMS using ADO. One of the nice things about connecting to MS Sql is that SqlOleDb is native to all Windows OS thru Win8 32 bit and there is no need for any third party OleDb provider. Nothing is needed on the client workstation and nothing to configure.
Here is a sample connection using ADO and the link to download the Free Ms Sql Server 2012 Express.
Rick Lipkin
Code: Select all
// Sql Server test program
#Include "FiveWin.ch"
//----------------------------
Func Main()
Local xProvider,xSource,xCatalog,xUserId,xPassword,xConnect
Local oRs,cSql,oErr,Saying
Public oCn
xPROVIDER := "SQLOLEDB" // oledb provider
xSOURCE := "RICKLIPKIN-PC\SQLEXPRESS" // sql server name
xCATALOG := "TRAVEL" // sql server database
xUSERID := "xxxxxxx"
xPASSWORD := "xxxxxxx"
xConnect := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD // connection string
Try
oCn := CREATEOBJECT( "ADODB.Connection" )
Catch
MsgInfo( "Could not create the ADO object for connection")
Return(.f.)
End Try
TRY
oCn:Open( xConnect ) // connection object
CATCH oErr
MsgInfo( "Could not open a Connection to Database "+xSource )
RETURN(.F.)
END TRY
oRs := TOleAuto():New( "ADODB.Recordset" )
oRs:CursorType := 1 // opendkeyset
oRs:CursorLocation := 3 // local cache
oRs:LockType := 3 // lockoportunistic
cSQL := "SELECT * From [Staff]"
TRY
oRs:Open( cSQL, oCn )
CATCH oErr
Saying := "Error in Opening STAFF table to"+chr(10)
Saying += "Import Legacy Data"+chr(10)
MsgInfo( Saying )
oCn:Close()
RETURN(.F.)
END TRY
xBrowse( oRs )
oRs:Close()
oCn:Close()
Return(.t.)
http://www.microsoft.com/en-us/download ... x?id=29062
Re: Acceder a MSSQL
Posted: Wed Dec 11, 2013 4:13 pm
by Willi Quintana
Error in "oCn: Open (xConnect)" something must be wrong, as would do to connect to the IP, my data server has the IP 192.168.1.99 or http:serverdat.net?
regards
Re: Acceder a MSSQL
Posted: Wed Dec 11, 2013 10:43 pm
by Rick Lipkin
Willi
You can use the IP address of your server or the Server name. Make sure your userid, password and database name are correct.
You can use the Microsoft SQL Management Studio that comes with Sql Server to login to your database to test your connection credentials.
Rick Lipkin
Re: Acceder a MSSQL
Posted: Fri Dec 27, 2013 2:36 pm
by juan carlos bellucci
Hola Rick , le hago una pregunta. usted seria tan amable si posee una conexión de esta forma para MySql. ya que veo esta mas avanzado que yo.
Re: Acceder a MSSQL
Posted: Fri Dec 27, 2013 4:02 pm
by Rick Lipkin
Juan
Take another look at my sample .. Ms Sql Server uses the built in Ole Provider called SqlOleDb which is on every Windows machine from Xp thru Windows 8.
There is nothing to configure or any setup needed on the workstation. That is what makes connecting to Ms Sql Server so nice. You do not need to distribute any Ole Client, run-time or Odbc to the desktop..
All you need to do is make sure your connection credentials are setup properly on your Sql Server and use ADO to manage and manipulate the data.
Rick Lipkin