從我的配置文件中看到的效果看起來像是這樣。.net的配置文件(無法傳入正確的值)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="loglocal" value="C:\here.txt" />
<add key="ConnString" value="Data Source=DBNAME;InitialCatalog=CataName;Integrated Security=True"/>
<add key="UppBound" value="100" />
<add key="LowBound" value="100" />
</appSettings>
</configuration
我試圖在某些價值觀傳遞到我的.NET程序,而唯一可行的是它是撿的目錄字符串loglocal
。
我可以通過我的界限進入查詢,但我無法傳入連接字符串並打開連接。
我試圖通過我自己的一套報價以及在長的查詢經過像以前一樣:
Dim SQLCONN as new SqlConnection("""" & nameofconfvalue & """")
僅供參考我的整個代碼看起來是這樣的。
Public Class Form1
Dim ConfUpperBound as Integer = Configuration.AppSettings("UppBound")
Dim ConfConnString as String = Configuration.AppSettings("ConnString")
Private Sub Button1_Click(ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
Dim SQLCONN as new SqlConnection("<either from config(fails) or hardcoded(works)>")
//fails on the below line (cannot open Connection)
SQLCONN.Open()
//I can successfully pass in values in query so I know i can connect to conf file
Dim SQLCMD as New SqlCommand("myquery etc etc")
SQLCMD.ExecuteNonQuery()
SQLCONN.Close()
End Sub
End Class
編輯:我能夠在字符串中傳遞完全使用Visual Studio 2005時,但在使用VS 2003年的時候和loiwer的.NET Framework它不會讓我,除非我硬編碼進去。
可以啓用/禁用VS的這些實例之一嗎?或者這可能只是舊版本.net的錯誤?我想我在2003年使用1.1 ??(將必須檢查)。
啊,不,我的互聯網代表! – sealz
你的連接字符串中的「數據源」的錯字怎麼樣:<... Data Spurce ... /> – MicSim
只是在這裏錯別字,沒有在實際代碼中的錯別字 – sealz