ADO.NET is a database technique using
C# code.
To make a connection string, do the following:
In
Visual Studio click
Tools →
Connect to Database... in the menu
In the "Add Connection" window, select
Server name:
Select the computer where the server is located for the database.
The server for the database is the program SQl Server
1) can be selected from the list [v]
2) You can write local, which means we will use SQL Server on your computer (locally).
Select or enter a database name:
Choose a database name
1) can be selected from the list [v]
Click Test Connection to see if there is a connection to the database (i.e. if we have specified server name and database name correctly)
Press the "Advanced..." button
Let's copy the text:
C#
In the C# code, we will use it to connect to the database
string connectionString = @"Data Source=localhost;Initial Catalog=MyDatabase1;Integrated Security=True;Trust Server Certificate=True";
C#
using Microsoft.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// connection string
string connectionString = @"Data Source=localhost;Initial Catalog=MyDatabase1;Integrated Security=True;Trust Server Certificate=True";
// connect to db
using (SqlConnection connection = new SqlConnection(connectionString))
{
// open db
connection.Open();
}
}
}
}