c# - 'SqlConnection' does not contain a constructor that takes 4 arguments -


this code:

public void sqldbconnect() {     sqlconnection conn = new sqlconnection("data source={0};user id={1};password={2};", server, user, password);     conn.open(); } 

i try make connection via server name, user , pass.

you need format string , pass string constructor (this c# 6 specific feature):

sqlconnection conn = new sqlconnection($"data source={server};user id={user};password={password};"); 

or in older c# versions can use string.format:

sqlconnection conn = new sqlconnection(string.format("data source={0};user id={1};password={2};", server, user, password)); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -