| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 634 人关注过本帖
标题:[求助]connection连接错误
只看楼主 加入收藏
shali
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-28
收藏
 问题点数:0 回复次数:3 
[求助]connection连接错误
System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.InvalidOperationException: ExecuteReader: Connection 属性尚未初始化。
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean executing)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at TeleCommServices.OperatorManageServices.CreateCard(String CardNo, Int32 CustomerID, String PUK, String PIN, String UserPwd, Decimal Balance, DateTime Expiration) in c:\inetpub\wwwroot\telecommservices\operatormanageservices.asmx.cs:line 620
--- 内部异常堆栈跟踪的结尾 ---卡号创建失败!
创建卡号成功!
卡号是:13777214072,余额是:50时间期限是:2007-12-28 12:33:47

我的服务代码如下:

[WebMethod]
public void CreateCard(string CardNo, int CustomerID, string PUK, string PIN,
string UserPwd, decimal Balance, DateTime Expiration)
{
string ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConnectionString;
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "usp_CreateCard";
comm.CommandType = CommandType.StoredProcedure;
SqlParameter param1 = new SqlParameter("@CardNo", SqlDbType.Char, 11);
param1.Direction = ParameterDirection.Input;
param1.Value = CardNo;
comm.Parameters.Add(param1);
SqlParameter param2 = new SqlParameter("@CustomerID", SqlDbType.Int);
param2.Direction = ParameterDirection.Input;
param2.Value = CustomerID;
comm.Parameters.Add(param2);
SqlParameter param3 = new SqlParameter("@PUK", SqlDbType.Char, 6);
param3.Direction = ParameterDirection.Input;
param3.Value = PUK;
comm.Parameters.Add(param3);
SqlParameter param4 = new SqlParameter("@PIN", SqlDbType.VarChar, 8);
param4.Direction = ParameterDirection.Input;
param4.Value = PIN;
comm.Parameters.Add(param4);
SqlParameter param5 = new SqlParameter("@UserPwd", SqlDbType.VarChar, 8);
param5.Direction = ParameterDirection.Input;
param5.Value = UserPwd;
comm.Parameters.Add(param5);
SqlParameter param6 = new SqlParameter("@Balance", SqlDbType.Decimal, 5);
param6.Direction = ParameterDirection.Input;
param6.Scale = 2;
param6.Value = Balance;
comm.Parameters.Add(param6);
SqlParameter param7 = new SqlParameter("@Expiration", SqlDbType.DateTime);
param7.Direction = ParameterDirection.Input;
param7.Value = Expiration;
comm.Parameters.Add(param7);
comm.ExecuteNonQuery();
conn.Close();
}

操作界面代码如下:

private void button1_Click_1(object sender, System.EventArgs e)
{
string CardNo = textBox1.Text;
string PIN = textBox2.Text;
string PUK = textBox3.Text;
int CustomerID = int.Parse(textBox4.Text);
decimal Balance = decimal.Parse(comboBox1.SelectedItem.ToString());
string UserPwd = textBox5.Text;
DateTime Expiration;
switch (comboBox1.SelectedItem.ToString())
{
case "100":
Expiration = DateTime.Now.AddYears(1);
break;
case "50":
Expiration = DateTime.Now.AddMonths(6);
break;
case "30":
Expiration = DateTime.Now.AddMonths(3);
break;

default:
Expiration = DateTime.Now;
break;
}
try
{
service.CreateCard(CardNo, CustomerID, PUK, PIN, UserPwd, Balance, Expiration);
}

catch (Exception ex)
{
richTextBox1.AppendText(ex.Message +"卡号创建失败!\r\n");
}
richTextBox1.AppendText("创建卡号成功!\r\n");
richTextBox1.AppendText("卡号是:"+CardNo+ ",余额是:"+
Balance+"时间期限是:"+Expiration+ "\r\n");

}

请各位高手指点怎么才能修改connection的错误

搜索更多相关主题的帖子: connection 
2007-06-28 12:36
shali
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-28
收藏
得分:0 

各位高手,救救我啊

2007-06-28 12:37
永不回头
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-9-27
收藏
得分:0 
在web.config里面配置一下这个语句

<appSettings/>
<connectionStrings>
<add name="liuwConnectionString" connectionString="Data Source=LIUWANG;Initial Catalog=liuw;User ID=sa" providerName="System.Data.SqlClient"/>
</connectionStrings>

[此贴子已经被作者于2007-6-28 13:51:58编辑过]


人生就是一个字:惨,惨,惨!
2007-06-28 13:36
shali
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-28
收藏
得分:0 
liuwConnectionString 是什么连接?在其他地方要配置吗?还有 Catalog=liuw; 不是很清楚
2007-07-01 21:44
快速回复:[求助]connection连接错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.085309 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved