How can i set an sql server connection string?
Actually you can use the SqlConnectionStringBuilder class to build your connection string. To build the connection string, you need to instantiate an object from that SqlConnectionStringBuilder and set their properties with the parameters you use to connect to the database. Then you can get the connection string from the ConnectionString property from the SqlConnectionStringBuilder object, as is shown in this example:
For example:
SqlConnectionStringBuilder sConnB = new SqlConnectionStringBuilder () { DataSource = "ServerName", InitialCatalog = "DatabaseName", UserID = "UserName", Password = "UserPassword" }.ConnectionString
SqlConnection conn = new SqlConnection(sConnB.ConnectionString);You can either use the new operator to make that directly.
For example:
SqlConnection conn = new SqlConnection( new SqlConnectionStringBuilder () { DataSource = "ServerName", InitialCatalog = "DatabaseName", UserID = "UserName", Password = "UserPassword" }.ConnectionString
);You can add more parameters to build your connection string. Remember that the parameters are defined by the values setted in the SqlConnectionStringBuilder object properties.
Also you can get the database connection string from the connection of Microsoft Visual Studio with the attached database. When you select the database, in the properties panel is shown the connection string.
The complete list of properties of the SqlConnectionStringBuilder class is listed in this page from the Microsoft MSDN site.
About the default user of SQL Server, sa means «system administrator» and its password varies according the SQL Server version. On this page you can see how the password varies.
SQL Server 2008/R2 Express User:sa Password: [blank password —
leave field empty to connect]
SQL Server 201x Express User:sa Password: Password123
SQL Server 20xx Web or Standard User:sa Password: will be the same
as your administrator or root user password at the time the VDS was
provisioned.
You can log in with the sa user in this login window at the start of SQL Server Database Manager. Like in this image:

Mysql
Connecting to MySQL is as easy as SQL Server. After installing either the MySQL .NET Connector or the MySQL NuGet packages, there’s a new provider available through config:
Replace config with web.config transformations
You probably don’t use the same database for local development and running your production environment. Being able to change a connection string depending on which environment your code is currently running, can be done in a number of ways. Cloud providers like Azure already have built-in support for overriding a connection string through app service configuration. But for someone not running on Azure, replacing connection strings can be done using Web.config Transformations.
To use another connection string when your code is running in release configuration, create or open the file named Web.Release.Config and paste the following configuration:
Sql server
Since most questions I get about connection strings are related to SQL Server, let’s start by looking at the possibilities there. The connection string will be identical no matter if you are connecting through Entity Framework, NHibernate, or using the raw SQL connection available in .NET.
The simplest SQL Server connection string looks like this:
Validating and error monitoring
Writing and testing connection strings mostly require you to launch your project and test the connection through a working site in the browser. Visual Studio has IntelliSense for the overall XML structure but not the content within the attributes. I always recommend people to use the Web.
config Validator to validate that the XML part is correct. If you are replacing production-specific connection strings with Web.config transformations, make sure to validate your transformation with the Web.config Transformation Tester tool.
As for monitoring for errors, I recommend you implement a good error monitoring solution on your website running in production. As the founder of elmah.io, I want to recommend you to use that. But there are similar solutions out there that will get you almost as far.
See how we can help you monitor your website for crashesMonitor your website
Вход в личный кабинет