Reputation: 639
I want to create a Windows form that lets the user choose a SQL Server instance to connect to and run a query on that database that should be there.
Is this possible? How do I create a dynamic SQL connection?
Upvotes: 0
Views: 69
Reputation: 161
To create a connection string you can use SqlConnectionStringBuilder, after that you can pass created connection string into SqlConnection:
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder
{
UserID = "Some User ID",
Password = "Some Database Password",
InitialCatalog = "Some Initial Catalog",
DataSource = "Some Data Source"
};
string connectionString = builder.ToString();
using (SqlConnection conn = new SqlConnection(connectionString))
{
//...
}
Upvotes: 2