FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Acceder a MSSQL
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
Acceder a MSSQL
Posted: Mon Dec 09, 2013 04:42 PM

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

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Acceder a MSSQL
Posted: Mon Dec 09, 2013 08:51 PM
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 (fw): Select all Collapse
// 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
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
Re: Acceder a MSSQL
Posted: Wed Dec 11, 2013 04:13 PM

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

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Acceder a MSSQL
Posted: Wed Dec 11, 2013 10:43 PM

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

Posts: 115
Joined: Sat Mar 07, 2009 09:36 PM
Re: Acceder a MSSQL
Posted: Fri Dec 27, 2013 02:36 PM

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.

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Acceder a MSSQL
Posted: Fri Dec 27, 2013 04:02 PM

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

Continue the discussion