crear tabla mysql

crear tabla mysql

Postby artu01 » Thu Feb 21, 2019 12:02 am

Amigos del Foro:
No me crea la Bd, cual es el error

Code: Select all  Expand view
 
  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
artu01
 
Posts: 400
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: crear tabla mysql

Postby nageswaragunupudi » Thu Feb 21, 2019 7: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: Select all  Expand view

cCad := "Provider=SQLOLEDB;Data Source=PYSASERVER;Initial Catalog=PysaBD;User ID=SA;Password=Pysa123456;"
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: crear tabla mssql

Postby artu01 » 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: Select all  Expand view


  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
artu01
 
Posts: 400
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: crear tabla mysql

Postby nageswaragunupudi » Fri Feb 22, 2019 2: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
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: crear tabla mysql

Postby csincuir » 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.
csincuir
 
Posts: 407
Joined: Sat Feb 03, 2007 6:36 am
Location: Guatemala

Re: crear tabla mysql

Postby artu01 » 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: Select all  Expand view

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
artu01
 
Posts: 400
Joined: Fri May 11, 2007 8:20 pm
Location: Lima


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], russimicro and 72 guests