How to rewrite Webconfig connection string at runtime

How to rewrite Webconfig connection string at runtime. I have an input text box for Server, UserName and Password. Is it possible to read from this text box?

+3
source share
1 answer

It depends on how you create the connection, but make sure it is possible.

Look at this site for the db connection string you are connecting to.

ConnectionStrings.com

For the SQL connection string, you will do something like

 Imports System.Data.SqlClient
 ...
 ...
 Dim conn As SqlConnection = New SqlConnection("Data Source=myServerAddress;Initial  Catalog=myDataBase;User Id=myUsername;Password=myPassword;")
 conn.Open

Replace the bits you want to change with the values ​​from your text box

eg

 Dim conn As SqlConnection = New SqlConnection("Data Source=" & txtServerAddr.Text & ";Initial  Catalog=" & txtDBName.Text & ";User Id=" & txtUser.Text & ";Password=" & txtPassword.Text & ";")

EDIT after editing your question

.

, . , (, Live, Test, Live # 2), web.config, -.

, web.config .. Microsoft . Web.config

, web.config " ",

" web.config . , , web.config, -".

+2

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


All Articles