I am trying to create a Data Layer for a C# Application in Visual Studio19. I am trying to connect to SQL Server 15.0.2010... I am using .Net 5.0 to and the following Usings:
The project will open the databases just fine. When I try to write the code, I get a multitude of errors not recognizing the SQL Command Object or the connection string.
using OnTarget2019.DataClasses;
using System;
using System.Data;
using System.Data.Common;
I would sincerely appreciate any help you can give me on how to do this properly.
ED Aymami
Jignesh KumarPosted Nov 5, 2023, 5:23 AM
Hello Edward,
I think you are missing few things in reference. As Mahesh Chand shared you need to refer "Microsoft.Data.SqlClient" namesapce to connect to sql server.
Please refer sample code as below,
Mahesh ChandPosted Nov 4, 2023, 9:30 PM
What is using OnTarget2019.DataClasses?
Can can use ADO.NET, and for that you must import the correct namespace in your class.
using Microsoft.Data.SqlClient;
Sam HobbsPosted Nov 4, 2023, 4:33 PM
There is much more that you did not say.
Edward AymamiPosted Nov 3, 2023, 9:08 PM
I also forgot to say that I did what you suggested before I asked my original question. I know the connection string, it is getting the right syntax and "Usings" to open the connection.
Sam HobbsPosted Nov 3, 2023, 8:27 PM
What do you mean by project will open the databases?
What is the code you are using for the database?
In Visual Studio, in the View menu, when you select SQL Server Object Explorer and right-click on the database, select Properties. In the properties is a connection string for the database. I think you can also get a connection string using SQL Server Management Studio (SSMS).