Creating SQL Database .mdf file using MFC , VC++ ?
-
Hello I am working on vc++ project in which i want to create the sql connection with my MFC application, so that i can create a new sql database (.mdf file) Is there any way to create a connection with sql server 2000 in VC++ and we also make a new sql database (.mdf) file . kindly look into the matter thanks
-
Hello I am working on vc++ project in which i want to create the sql connection with my MFC application, so that i can create a new sql database (.mdf file) Is there any way to create a connection with sql server 2000 in VC++ and we also make a new sql database (.mdf) file . kindly look into the matter thanks
Hi, its possible by using ado. In order to do let it work, you must preform some setup tasks. 1. Import the Library place the following line in the stdafx.h file. the msado15.dll file should be located in the project directory.
#import "msado15.dll" no_namespace rename ("EOF", "adoEOF")
2. Initialize the ole lib Ado works with oledb.
if(OleInitialize(NULL) != S_OK) { // Error, stop }
3. Connect to the database Replace USER_ID, PASSWORD, SQLSERVERNAME, DATABASE_NAME with the correct values
CString strConnectionString; strConnectionString.Format("uid=USER_ID;pwd=PASSWORD;driver={SQL Server};server=SQLSERVERNAME;database=DATABASE_NAME"); _ConnectionPtr ptrDbCon; ptrDbCon.CreateInstance(__uuidof(Connection)); ptrDbCon->Open((_bstr_t)strConnectionString, "", "", -1);
You sould connect to the master database in order to create another database. Just execute the queries to create an database as you need.
codito ergo sum
-
Hi, its possible by using ado. In order to do let it work, you must preform some setup tasks. 1. Import the Library place the following line in the stdafx.h file. the msado15.dll file should be located in the project directory.
#import "msado15.dll" no_namespace rename ("EOF", "adoEOF")
2. Initialize the ole lib Ado works with oledb.
if(OleInitialize(NULL) != S_OK) { // Error, stop }
3. Connect to the database Replace USER_ID, PASSWORD, SQLSERVERNAME, DATABASE_NAME with the correct values
CString strConnectionString; strConnectionString.Format("uid=USER_ID;pwd=PASSWORD;driver={SQL Server};server=SQLSERVERNAME;database=DATABASE_NAME"); _ConnectionPtr ptrDbCon; ptrDbCon.CreateInstance(__uuidof(Connection)); ptrDbCon->Open((_bstr_t)strConnectionString, "", "", -1);
You sould connect to the master database in order to create another database. Just execute the queries to create an database as you need.
codito ergo sum
-
Hello I am working on vc++ project in which i want to create the sql connection with my MFC application, so that i can create a new sql database (.mdf file) Is there any way to create a connection with sql server 2000 in VC++ and we also make a new sql database (.mdf) file . kindly look into the matter thanks
Have you tried using the CREATE DATABASE command?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Hello I am working on vc++ project in which i want to create the sql connection with my MFC application, so that i can create a new sql database (.mdf file) Is there any way to create a connection with sql server 2000 in VC++ and we also make a new sql database (.mdf) file . kindly look into the matter thanks
Did you see Databse section on the codeproject?
-
Have you tried using the CREATE DATABASE command?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
As per ur suggestion i use create databse command and i able to create Database ,now i want to create Table in that database and i am using create table command bt it give an error message IDispatch error #3092 ,code: 0x80040e14 ,source :Microsoft OLEDB provider for sql server ,Description: There is already an object named 'myatble' in the database. Bt there is no table present in the database with name myTable. Pls help me regarding this.
-
As per ur suggestion i use create databse command and i able to create Database ,now i want to create Table in that database and i am using create table command bt it give an error message IDispatch error #3092 ,code: 0x80040e14 ,source :Microsoft OLEDB provider for sql server ,Description: There is already an object named 'myatble' in the database. Bt there is no table present in the database with name myTable. Pls help me regarding this.
aaaan wrote:
Bt there is no table present in the database with name myTable.
But the error message you received mentioned 'myatble'.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne