且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

web.config中的连接字符串

更新时间:2022-10-22 11:39:39

我会尝试在connectionstring中的userid周围放置括号或单引号,因为它有短划线。


  string  connStr = ConfigurationManager.ConnectionStrings [  myConnectionString]。ConnectionString ; 



试试这样..






我认为您在web.config中给出的连接字符串名称不同

web.config中的连接字符串应该如下所示....

 <   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    /  >  



否则更改与您在服务器端代码(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