Since we will connect to the MS SQL Server database, we will use the providerName for SQL Server, the functionality of which is contained in the namespace.
And the third attribute providerName sets the namespace of the data provider. The connectionString attribute actually stores the connection string, that is all the text that we defined above in the Main method. In this case the connection string is called “DefaultConnection”. We can use many connection strings in an application and accordingly we can also define many elements in a file.Įach connection string has a name defined by the name attribute. In this node connection strings are defined using the element. To define all connections in the program, a new node is added within the node. In our case, since we have created a console application project, we should have an App.config file in the project, which currently has the following definition: Although the application can also use other ways to define the configuration. In desktop application projects it is App.config file, while in web applications it is mostly Web.config file. A much more flexible path represents its definition in special configuration files of an application. its definition in application code) is usually rarely used. Hard coding of the connection string (i.e. Integrated Security: establishes authentication.Initial Catalog: indicates the name of the database on the server.If the database server name is different, then it should be used accordingly. Since a slash is used in the string, the character is placed at the beginning of the string. Data Source: points to the server name.In this case, to connect to the previously created usersdb _1 database, we define the connection string from three parameters: The connection string represents a set of parameters in the form of key=value pairs. The connection string represents a set of parameters
How to Create Connection String For SQL Server.To connect to the database, we need to create and use the SqlConnection object.The connection string represents a set of parameters.