Winform加入MS SQL连线字串
App.config中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<connectionStrings>
<!-- '*** 資料庫 連結字串*** -->
<add name="DBcs"
connectionString="Data Source=210.65.10.150;Initial Catalog=STSP;Persist Security Info=True;User ID=sa;Password=jsene2wsx#EDC"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
连线字串:
Private Sub alarm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Conn As SqlConnection = New SqlConnection
Conn.ConnectionString = ConfigurationManager.ConnectionStrings("Dbcs").ConnectionString()
Conn.Open()
End Sub
加入连线字串之前须参照:
文章翻译自:dotblogs

本文介绍如何在Winform应用程序中配置并使用MSSQL资料库连线。具体包括在App.config文件中设置资料库连线字串的方法,以及在程式码中通过ConfigurationManager读取并建立SQL连线的过程。
1万+

被折叠的 条评论
为什么被折叠?



