Click here to Skip to main content
15,558,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello evreyone,

Can anybody please let me know which connection string to be used for MS SQl server database connection for a Windows Desktop Application with MFC?

I am doing this project in Visual Studio 2019, where i have connected to the database for the project. With Tools-> Connect to DataBase-> Provider (MS SQL Server), W10SQLEXPRESS(local server). Also I can see my tables created in the SQL Server explorer in Visual Studio.

What I have tried:

I have tried to open a connection with the SQL server, but results in failure. If anyone body have done a similar Project, Could you please let me know the connection string for opening a connection with SQL server?

My data source is Microsoft SQL Servver

_bstr_t StrConnection = "Provider=sqloledb;Data Source=W10SQLEXPRESS;"
"Initial Catalog=Employee;"
"Integrated Security=SSPI;"
Also I am using Windows Nt Authentication and also wanted to connect the server locally

If anybody has an idea , please reply. It would be a great help for me to move further with the Project.
Thanks in advance.
Updated 30-Sep-20 22:48pm
Maciej Los 1-Oct-20 3:37am    
Can you connect to your MS server instance via MS SQL Server Management Studio?

We can't tell you exactly what string to use - we have no access to your system, the network it's relying on, or the server instance you wish to connect to; you need all those to even begin assembling a connection string.

Have a look here: Simple SQL Connection String Creation[^] - it may help.
Share this answer
Share this answer
Start by reading MSDN documentation: Database Support, MFC Application Wizard | Microsoft Docs[^]

You've got 2 options to connect to your sql server instance, via: OleDb or ODBC.

A proper connection string for Microsoft ODBC driver:
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Trusted_Connection=Yes;

See: Microsoft SQL Server ODBC Driver Connection Strings -[^]

Good luck!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900