FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour crear tabla mysql
Posts: 400
Joined: Fri May 11, 2007 08:20 PM
crear tabla mysql
Posted: Thu Feb 21, 2019 12:02 AM
Amigos del Foro:
No me crea la Bd, cual es el error

Code (fw): Select all Collapse
  
  cCad := "Provider=SQLOLEDB;"
  cCad += "Server=PYSASERVER;"
  cCad += "Database=PysaBD;Uid=sa;Pwd=Pysa123456;"
  TRY
    oCon := CreateObject( "ADODB.Connection" )
  CATCH oError
     MsgStop( oError:Description )
  END
   TRY
     oCon:Open( cCad )
   CATCH oErr
     MsgInfo( "Could not open Connection to Database " )
     RETURN(.F.)
   END TRY

   cSql:="CREATE TABLE IF NOT EXISTS cabguit AS (SELECT * FROM cabguia)"

   Try
      oCon:Execute( cSQL )
   Catch
      MsgInfo( "Table Create BIN Failed" )
   End try
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: crear tabla mysql
Posted: Thu Feb 21, 2019 07:09 AM
Title of this topic says "MySql".
But you are trying to connect to Microsoft SQL Server. (MSSQL).

This is the correct connection string to be used to connect to MSSQL (not MySql)

Code (fw): Select all Collapse
cCad := "Provider=SQLOLEDB;Data Source=PYSASERVER;Initial Catalog=PysaBD;User ID=SA;Password=Pysa123456;"
Regards



G. N. Rao.

Hyderabad, India
Posts: 400
Joined: Fri May 11, 2007 08:20 PM
Re: crear tabla mssql
Posted: Fri Feb 22, 2019 12:54 AM
Mr. Rao:
You have right is MSSQL, not MySQL , typing error
its ok with the connection chain
selects, inserts, deletes do without problem
but i cant créate table
it got this error

Error BASE/1004 Message not found: LOGICAL:EXEC


Gente:

Estoy migrando mis tablas de dbf a sql, logro conectarme, hacer consultas, pero necesito crear tablas, es ahi donde no puedo
sale el msje de arriba

Code (fw): Select all Collapse
  xPROVIDER := "SQLOLEDB"                  
  xSOURCE   := "PYSASERVER"                
  xCATALOG  := "PysaBD"                    
  xUSERID   := "sa"
  xPASSWORD := "Pysa123456"
  xConnect  := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD

  TRY
    oCon1 := CreateObject( "ADODB.Connection" )
    oCon1:Open( xConnect )
  CATCH oError
     MsgStop( oError:Description )
  END
// first option not run
   cSQL := "CREATE TABLE Bin"
   cSQL += "( "
   cSQL += "[BIN]       char(50) NOT NULL, "
   cSQL += "CONSTRAINT PK_BIN PRIMARY KEY ( BIN )"
   cSQL += " )"

   // second option also not run
   //cSql:="CREATE TABLE IF NOT EXISTS regtempo AS (SELECT * FROM cabguia)" 

   Try
      oCon1:Execute( cSQL )
   Catch
      MsgInfo( "Table Create BIN Failed" )
   End try
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: crear tabla mysql
Posted: Fri Feb 22, 2019 02:46 AM

MySql syntax does not always work in MSSql.

For example, CREATE ..IF NOT EXISTS .. does not work in MsSql

Please study MSSQL syntax
Suggest

http://www.w3schools.com

Regards



G. N. Rao.

Hyderabad, India
Posts: 476
Joined: Sat Feb 03, 2007 06:36 AM
Re: crear tabla mysql
Posted: Fri Feb 22, 2019 12:07 PM

Artu, prueba con esta instrucción a ver si te crea la tabla (funciona tanto para MySQL como MSSql)

CREATE TABLE tablaprueba
(
clave VARCHAR(7) NOT NULL,
hechopor VARCHAR(60) NOT NULL,
valorint INT(1) NOT NULL DEFAULT 1,
PRIMARY KEY (clave)
);

Saludos cordiales,

Carlos.

Posts: 400
Joined: Fri May 11, 2007 08:20 PM
Re: crear tabla mysql
Posted: Sat Feb 23, 2019 12:39 AM
nageswaragunupudi wrote:Please study MSSQL syntax

Thank mr. rao, i shall do so

csincuir wrote:CREATE TABLE tablaprueba( clave VARCHAR(7) NOT NULL, hechopor VARCHAR(60) NOT NULL, valorint INT(1) NOT NULL DEFAULT 1, PRIMARY KEY (clave) );


Gracias csincuir, así me funciono

Code (fw): Select all Collapse
cSQL := "CREATE TABLE #prueba"
cSQL += "("
cSQL += "clave VARCHAR(7) NOT NULL,"
cSQL += "hechopor VARCHAR(60) NOT NULL,"
cSQL += "valor INT NOT NULL DEFAULT 1"
cSQL += ")"
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql

Continue the discussion