web.config中的连接字符串 [英] connection string in web.config
问题描述
我的web.config:
< configuration>
< connectionstrings>
< add name =mywork_str>
connectionString =Provider = SQLOLEDB .1;集成安全性= SSPI;持久安全信息=假;用户ID = mywork-PC;初始目录=作业;数据源= myDB/>
< system.web>
< compilation debug =truestrict =falseexplicit =truetargetframework = 4.0>
在我的源代码中:Visual 2010专业(Visual Basic)
Dim myConnectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings [mywork_str]。ConnectionStrings.Tostring
错误我得到:
标识符预期,下划线位于[mywork_str]的(双引号)
任何人都知道如何解决它。非常感谢
谢谢
查理
我会尝试在connectionstring中的userid周围放置括号或单引号,因为它有短划线。
string connStr = ConfigurationManager.ConnectionStrings [ myConnectionString]。ConnectionString ;
试试这样..
我认为您在web.config中给出的连接字符串名称不同
web.config中的连接字符串应该如下所示....
< add < span class =code-attribute> name = mywork_str connectionstring = Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info = False; User ID = mywork-PC; Initial Catalog = homework; Data Source = myDB / >
否则更改与您在服务器端代码(mywork_str)中提供的字符串匹配的连接字符串的名称。
我希望这对您有所帮助。
问候,
RK
Would you please help? I put connection string in my web.config
My web.config:
<configuration>
<connectionstrings>
<add name="mywork_str">
connectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=mywork-PC;Initial Catalog=homework;Data Source=myDB"/>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetframework="4.0">
in my source code:Visual 2010 professional (Visual Basic)
Dim myConnectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings["mywork_str"].ConnectionStrings.Tostring
ERROR I get:
Identifier expected , the underline placed under " (double quote) of ["mywork_str"]
Anyone knows how to fix it . I am so appreciated
Thanks
Charlie
I would try putting brackets or single quotes around the userid in the connectionstring, Since it has that dash.
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
Try like this..
Hi,
I think the connection string name you have given as different in web.config
Connection string in your web.config should look like this....
<add name="mywork_str" connectionstring="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=mywork-PC;Initial Catalog=homework;Data Source=myDB" />
Otherwise change the name of the connection string that matches the string that you have gave in server side code(mywork_str).
I hope this helps you a bit.
Regards,
RK
这篇关于web.config中的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!