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

python - Best design pattern for collection of objects -

go - serving up pdfs using golang -

python - django admin: changing the way a field (w/ relationship to another model) is submitted on a form so that it can be submitted multiple times -