elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
27 Mayo 2012, 02:46  


Tema destacado: [AIO elhacker.NET] Compilación herramientas análisis y desinfección malware

+  Foro de elhacker.net
|-+  Foros Generales
| |-+  Dudas Generales
| | |-+  conectar visual studio 2010 c++ con sql server 2008
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: conectar visual studio 2010 c++ con sql server 2008  (Leído 961 veces)
karmankk

Desconectado Desconectado

Mensajes: 1


Ver Perfil
conectar visual studio 2010 c++ con sql server 2008
« en: 14 Febrero 2012, 09:51 »

Hola amigos, tengo un pequeño programa en c++ implementado en VS2010 que me gustaría que utilizase algunos valores de una base de datos que tengo creada en SQL server 2008.
Alguno de ustedes sabría decirme los pasos a seguir?? he visto diferentes maneras, con SQLAPI.h con, el driver OBDC, ASP...me gustaría hacerlo con el OBDC que es lo que mejor he entendido.
Buscando por internet he encontrado información pero siempre los cógigos que encuentro para conectarme a la base de datos me dan errores...creo que puede ser porque no añado bien los errores. Si me aclaráis esto ultimo os lo agradecería también.
Aqí os pongo por ejemplo uno de los muchos códigos que he encontrado y que no tengo narices de echarlo a rodar....


Un saludo grande a todos y gracias de antemano.


The connection of c++ program to database are explain step by step. To make aconnection follow the steps:
1). Include the Header Files

# include statements at the beginning of your programs:
#include <sql.h>
#include<sqltypes.h>
#include<sqlext.h>

2). Open a Connection to a Database

Set the environment handle:
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv);
Set ODBC Driver version:
SQLSetEnvAttr(hdlEnv,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC30);
Set the connection handle:
SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlConn);
Connect to the database:
SQLConnect(hdlConn, (SQLCHAR*)dsnName,SQL_NTS,(SQLCHAR*)userID,SQL_NTS, (SQLCHAR*)passwd, SQL_NTS);

3). Choose Driver

•DSN – Data Source Name
•Open the GUI ODBC Administrator (ODBCConfig)
•Choose the appropriate ODBC driver
•Provide a meaningful name to the DSN
•Specify the server and the host string (host string is required if the server is running on a different machine)

4). Query the Database

Querying the database involves the following steps:
–Creating a Statement
SQLAllocHandle(SQL_HANDLE_STMT, hdlDbc, &hdlStmt);
It allocates the memory for the statement handle. The database handle obtained during connection phase is passed as the second argument.
– Executing a Query
SQLExecDirect(hdlStmt, stmt, SQL_NTS);
It executes the query, which is passed in as SQLCHAR* in the second argument.

5). Extract the Data out of the Executed Query

SQLGetData(hStmt,colNum,type,retVal,buffLength,&cbData);
It extracts data from table as void* data and places it in retVal
colNum refers to the column number provided in the SELECT statement in SQLExecDirect()
Type is one of the standard ODBC data types
example: DT_STRING à for a string data type
DT_DOUBLE à for a double data type
buffLength is the estimated size of the expected data
cbData is the actual size of the data

6). Traverse Through the Results

SQLFetch(hStmt);
Fetches the next record
hStmt is the statement handle obtained using SQLAllocHandle
If a record is available, It returns SQL_SUCCEEDED

7). Close the Statement and the Connection

SQLFreeHandle(SQL_HANDLE_STMT, hdlStmt);
It closes and de-allocates the memory reserved for the statement handle
SQLFreeHandle(SQL_HANDLE_DBC, hdlConn);
It disconnects and de-allocates the memory reserved for the connection handle
SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv);
It de-allocates the memory occupied by the environment handle


the above code will connect your c++ program with a sql database


En línea
Cazs03

Desconectado Desconectado

Mensajes: 25


Ver Perfil
Re: conectar visual studio 2010 c++ con sql server 2008
« Respuesta #1 en: 23 Febrero 2012, 15:29 »

nose programar en vb pero se de sql tienes que indicar el nombre de la bd la ip y el usurio con una sql a connectar


En línea
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
MS Visual Studio 2008
Programación General
neo8 4 874 Último mensaje 9 Agosto 2008, 07:02
por sangano
Visual Studio 2005 o 2008?
Programación C/C++
EvilGoblin 4 737 Último mensaje 8 Marzo 2009, 18:20
por vertexSymphony
Problema con Visual Studio 2008, Visual Source Safe 2005.
.NET
davidesgt 0 2,239 Último mensaje 14 Octubre 2009, 17:32
por davidesgt
ABM En Visual Studio 2008 + access
.NET
chompi_cachorro 4 3,787 Último mensaje 3 Noviembre 2009, 02:05
por chompi_cachorro
Conexion Remota Visual Studio 2010 con Sql Server 2008
.NET
Red Chasqui 1 626 Último mensaje 27 Marzo 2012, 15:04
por Bulld0z3r
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines