Extract connection string from web. config

Source: Internet
Author: User
Tags connectionstrings

System. configuration. configuartinsettings. receivettings ["connstring"]. tostring ();

This indicates that the connection string is extracted from web. config.


However, in visual stuido 2005, the following must be used. Otherwise, the connectstring attribute may not have been initially modified.

Modified to the following and succeeded

System. configuration. configurationmanager. connectionstrings ["ahaoaconnectionstring"]. tostring ();


Sqlconnection conn = new sqlconnection (system. configuration. configurationmanager. connectionstrings ["xpxponstring"]. tostring ());

Sqlcommand comm;
Datetime dt = datetime. now;

string stradduser = "insert into user_reg (user_name, user_pass, user_question, user_answer, user_mail, user_regtime) values (@ username, @ password, @ question, @ answer, @ mail, @ time) ";

sqlparameter parmuser = new sqlparameter ("@ username", sqldbtype. varchar);
sqlparameter parmpass = new sqlparameter ("@ password", sqldbtype. varchar);
sqlparameter parmques = new sqlparameter ("@ question", sqldbtype. varchar);
sqlparameter parmanswer = new sqlparameter ("@ answer", sqldbtype. varchar);
sqlparameter parmmail = new sqlparameter ("@ mail", sqldbtype. varchar);
sqlparameter parmtime = new sqlparameter ("@ time", sqldbtype. datetime);
comm = new sqlcommand (stradduser, Conn);

Parmuser. value = tbuser. text;
Parmpass. value = tbpass. text;
Parmques. value = tbqiz. text;
Parmanswer. value = tbanswer. text;
Parmmail. value = tbmail. text;
Parmtime. value = DT;

Comm. Parameters. Add (parmuser );
Comm. Parameters. Add (parmpass );
Comm. Parameters. Add (parmques );
Comm. Parameters. Add (parmanswer );
Comm. Parameters. Add (parmmail );
Comm. Parameters. Add (parmtime );

conn. open ();
comm. executenonquery ();
conn. Close ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.