<?xml version="1.0" encoding="utf-8" ?> <configuration> <ConnectionStrings> <add key="sleepTime" value="60000"/> <add name="Sqlconn" value="Data Source=NICHOLAS_D-PC;User ID=sa;Password=sa;Database=Text" /> <add name="port" value="5"/> </ConnectionStrings> <appSettings> </appSettings> </configuration>
string con = ConfigurationManager.ConnectionStrings["Sqlconn"].ConnectionString; SqlConnection conn = new SqlConnection(con); conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; //设置cmd的类型为存储过程 cmd.CommandText = "EXEC usp_CallSceneStep"; cmd.Connection = conn; SqlParameter pCustomerID = new SqlParameter(); pCustomerID.ParameterName = "@CustomerID"; pCustomerID.SqlDbType = SqlDbType.NChar; pCustomerID.Value = "ALFKI"; cmd.Parameters.Add(pCustomerID);
解决了
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="sleepTime" value="60000"/> <add key="Sqlconn" value="Data Source=ADMIN-PC;User ID=sa;Password=sa;Database=Text" /> <add key="port" value="5"/> </appSettings> </configuration>
系统的后缀名有没有显示出来?是不是错误的修改了文件名?看文件是web.config,但其实是web.config.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="sleepTime" value="60000"/> <add key="Sqlconn" value="Data Source=ADMIN-PC;User ID=sa;Password=sa;Database=Text" /> <add key="port" value="5"/> </appSettings> </configuration>