Connection methods that involve configuration files:
Way One:
in the configuration file:<configuration> <appSettings> <add key="ConnectionString"Value="The name of the data source= server; Initial catalog= the name of the database to connect to; User id= Database login name; password= Database Login SecretCode"/></appSettings><configuration>to get the database connection string in your code: Public Static ReadOnly stringConnectionString = configurationmanager.appsettings["ConnectionString"];//ConnectionString is the value of the key in the configuration file
Way two:
in the configuration file:<configuration> <connectionStrings> <add name="MyDb"connectionstring="The name of the data source= server; Initial catalog= the name of the database to connect to; User id= Database login name; password= Database Login Password"ProviderName="System.Data.SqlClient"/> </connectionStrings><configuration>Get the database connection string in your code: Public Static ReadOnly stringstr = configurationmanager.connectionstrings["MyDb"]. ToString ();//MyDB is the value of name in the configuration file
Does not involve how the configuration file is connected:
The name of the new@ "data source= server; Initial catalog= the name of the database to which you want to connect; User id= Database login name; password= Database login Password ";
Three ways to connect to a SQL Server database