您的位置:程序门 -> .net技术 -> asp.net



菜鸟学.net   connectionstring 属性尚未初始化...


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


菜鸟学.net connectionstring 属性尚未初始化...[已结贴,结贴人:magicevy]
发表于:2007-05-14 19:41:29 楼主
protected   void   button1_click(object   sender,   eventargs   e)
        {
                string   strconnection   =   system.configuration.configurationsettings.appsettings[ "strconnection "];
                string   strcmd= "select   count(*)   from   userinfo   where   name   = ' "+   textbox1.text   + " '   and   password   =   ' "+   textbox2.text   + " ' ";
                sqlconnection   myconnection   =   new   sqlconnection();
                myconnection.connectionstring   =   strconnection;

                sqlcommand   mycommand=new   sqlcommand(strcmd,myconnection);
                mycommand.connection.open();

                int   flag=(int)mycommand.EXECutescalar();
                mycommand.connection.close();
                myconnection.close();
                if   (flag> 0)
                {      
                        session[ "username "]=textbox1.text;
                        response.redirect( "main.aspx ");
                }
                else
                {
                        label1.text= "对不起!请输入正确的用户名和密码 ";
                        textbox2.text= " ";
                }
        }


异常详细信息:   system.invalidoperationexception:   connectionstring   属性尚未初始化。

源错误:  


行   21:  
行   22:                   sqlcommand   mycommand=new   sqlcommand(strcmd,myconnection);
行   23:                   mycommand.connection.open();
行   24:  
行   25:                   int   flag=(int)mycommand.EXECutescalar();
 

源文件:   c:\inetpub\wwwroot\default.aspx.cs         行:   23  


要怎么修改?
发表于:2007-05-14 19:49:401楼 得分:0
system.configuration.configurationsettings.appsettings[ "strconnection "];
============================================================

你的web.config文件里连接字符串是   strconnection吗?
发表于:2007-05-14 20:12:592楼 得分:0
我的web.config里是这样的:
<connectionstrings>
               
                <add   key= "strconnection "   value= "server=(local);database=vod;persist   security   info=true;password=;user   id=sa; "   />
        </connectionstrings>
发表于:2007-05-14 20:28:093楼 得分:20
换成
<appsettings>
              <add   key= "strconnection "   value= "server=(local);database=vod;persist   security   info=true;password=;user   id=sa; "   />
</appsettings>
试试
发表于:2007-05-14 20:28:504楼 得分:0
system.configuration.configurationsettings.appsettings[ "strconnection "];
这种设置不是过时了吗?


快速检索

最新资讯
热门点击