当前位置:网站首页>C#将数据库连接方式写到配置文件中
C#将数据库连接方式写到配置文件中
2022-07-15 19:16:00 【susan花雨】
- asp.net 项目配置文件:Web.config;winfrom项目配置文件:App.config
写入下面代码
根据需要自行选择本地或者sa账户
<configuration>
<!--数据库连接-本地-->
<!--<connectionStrings>
<add name="connectionString"
connectionString="server=.;Initial Catalog=ss;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>-->
<!--数据库连接-sa-->
<connectionStrings>
<!--数据库 jjq_connStr_SQL Server-->
<add name="ConnectionString"
connectionString="Data Source=10.xx.xx.xx;Initial Catalog=D_xx;User ID=sa;Password=sa;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
2.cs代码中:
using System.Configuration;//引用
private static string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
边栏推荐
猜你喜欢

响应式织梦模板家居家具建材类网站

(2021 Niuke multi school V) k-king of range (monotonous queue /st table)

实现有效的机器人教育培训管理模式

(2021 Niuke multi school III) j-counting triangles (thinking)

MySQL version upgrade experience

推荐系统究竟是什么?

解析结合劳动教育的steam新课程

Global registration component

Comprehensive explanation of e-commerce crawler API

【微服务】Nacos数据持久化以及集群的搭建
随机推荐
金融、生物医药、集成电路,上海巨头行业用AI加持核心竞争力
目前网上开户炒股安全吗?
SSH 学习杂记
【LeetCode】9. Flood Fill·图像渲染
(codeforce631) c.report (monotone stack)
error: expected identifier or ‘(‘extern “C“ {
(codeforce1699) a & B (construction)
v-model与.sync修饰符的区别
edusoho企培版 外部资讯抓取 有时无法获取图片问题/无法获取微信公众号图片
HMS core graphics and image technology shows the latest functions and application scenarios, and accelerates the construction of digital intelligence life
Real time user session tracking using eventlog analyzer
小米摄像头修改wifi
小目标检测2_OHEM
好玩的ping命令
[matlab project practice] digital signal processing system based on GUI
KingbaseES V8R6 ksql 关闭自动提交
Responsive dream weaving template home furniture building materials website
Insight into the puzzle of database, 2022 Jincang innovative product launch was held
【开源可信隐私计算框架 “隐语”】蚂蚁宣布面向全球开发者正式开源
SQL也能做AI ?没错!MLOps Meetup V3 回顾|OpenMLBD+SQLFlow+Byzer