| |

VerySource

 Forgot password?
 Register
Search
View: 609|Reply: 1

The database connection is configured in web.config, but how can he connect in .NET?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-13 12:00:01
| Show all posts |Read mode
web.config: <appSettings>
<add key = "sqlConnection" value = "Persist Security Info = False; Data Source = 127.0.0.1\NEWS; Initial Catalog = NEWS; User ID = sa; Password =;" />
Ranch
Ranch
  </ appSettings>



string sql = "select * from Log";
SqlConnection conn = new SqlConnection ("server = user65; uid = sa; pwd =; database = NEWS"); [Write once every call, it's annoying, how to write it in CONFIG?
conn.Open ();
SqlCommand com = new SqlCommand (sql, conn);
Ranch
ShowLog.DataSource = com.ExecuteReader ();
ShowLog.DataBind ();
conn.Close ();
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-10 22:15:01
| Show all posts
string SQLConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("sqlConnection"));
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list