Connect to sql server through winnet win.net application

I am making a simple C # .net winform application with form1 that will connect to sql server.

I want the application to ask the user to enter a name and password for the connection before establishing a connection to the sql server.

for this, what should I do:

enter the username and password in the two text fields and pass them to the connection string or should I pass them to the app.config file and then use the line from the app.config file in form1.cs?

will this be okay with security issues? if not, what are other ways to accomplish this?

+3
source share
5 answers

I would do this:

Update:

, :

<configuration>
  <connectionStrings>
     <add name="MyConnStr" 
          connectionString="server=A9;database=MyDB;" />
  </connectionStrings>
</configuration>

"" ( - !) SqlConnectionStringBuilder:

string myConnStr = ConfigurationManager.ConnectionStrings["MyConnStr"].ConnectionString;

SqlConnectionStringBuilder sqlcsb = new SqlConnectionStringBuilder(myConnStr);

:

sqlcsb.UserID = tbxUserName.Text.Trim();
sqlcsb.Password = tbxPassword.Text.Trim();

SqlConnectionStringBuilder:

string completeConnStr = sqlcsb.ConnectionString;

using(SqlConnection _con = new SqlConnection(completeConnStr))
{
   // do whatever you need to do here....
}
+5

. app.Config .

+1

SQL Windows. , Windows , .

? ?

+1
+1

Sql authentication data is always stored separately from the application authentication data (there are exceptions ... for example: ur creating their own version of sql server client)

  • Save database connection data in app.config.
  • Ideally, one user with application level restrictions should be enabled.
  • The input you are talking about is an authentication module that exists in C #. for example: Windows authentication, forms authentication, etc.
+1
source

Source: https://habr.com/ru/post/1795423/


All Articles