我是新的WCF,我想在IIS上部署我的WCF示例应用程序,此应用程序在VS2008的调试模式下正常工作,此应用程序验证WCF具有以下代码的消息。我这样做是这样,我已经添加了导致的.dll的web.config和Service.svc在wwwroot目录,我还增加了连接字符串中的IIS管理器,它是在IIS中部署WCF应用程序,但SQL Server数据库连接不起作用
Server=MyPC\SQLEXPRESS;Database=MySampleDb;Integrated Security=true
我使用Windows集成安全性。我使用相同的连接字符串在数据库类连接,但我得到以下异常,
请指引我部署的应用
在Validater
public override void Validate(string userName, string password)
{
ValidateUser(userName, password);
}
public static bool ValidateUser(string userName, string password)
{
if (!string.IsNullOrEmpty(userName))
{
ICustomer customer = GetCustomerByUsername(userName);
if (customer ==null)
{
throw new exception("User Not found.");
}
else
{
return true;
}
}
else
{
throw new FaultException("User name is required!");
}
}
public static ICustomer GetCustomerByUsername(string username)
{
try
{
//ConnectionString= "Server=MyPC\SQLEXPRESS;Database=MySampleDb;Integrated Security=true";
OpenConnection();
var cmd = new SqlCommand("GetUserByUsername", _connection) { CommandType = CommandType.StoredProcedure };
cmd.Parameters.Add("Username", username);
connState = _connection.State.ToString();
if (_connection.State == ConnectionState.Closed)
{
OpenConnection();
}
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
ICustomer customer = null;
customer = ExtractCustomerFromDataReader(dr)[0];
dr.Close();
return customer;
}
catch (Exception e)
{
throw new Exception(e.Message + Environment.NewLine + e.StackTrace);
}
finally
{
CloseConnection();
}
}
例外:
ExecuteReader需要一个打开的和可用的Connection。连接的 当前状态已关闭。在在 System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(字符串 方法,SqlCommand的命令) System.Data.SqlClient.SqlConnection.GetOpenConnection(字符串 方法)在 System.Data.SqlClient.SqlCommand.ValidateCommand(字符串 方法,布尔异步)在 System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,runBehavior runBehavior, 布尔returnStream,字符串方法, DbAsyncResult结果)在 System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior, RunBehavior runBehavior, 布尔returnStream,String方法) 在 System.Data.SqlClient.SqlCommand.ExecuteReader(的CommandBehavior 行为,字符串方法)在 System.Data.SqlClient.SqlCommand.ExecuteReader(的CommandBehavior 行为)在 Aschrafi.MobileZollServer.Services.DatabaseHelper.GetCustomerByUsername(字符串 用户名)在
我想我错过了数据库设置或在IIS管理器的网站设置的一些观点。在IIS中进行WCF部署并验证WCF通信的某些教程或文章链接将非常感谢。
在此先感谢。
谢谢您的回答,我应该使用哪个用户。 如果我必须创建新的应该是 登录名: 默认架构: 拥有架构。和角色成员 以及如何查看C#代码和IIS管理器中的连接字符串。 – DronBoard 2010-09-20 20:17:59
@DronBoard:用附加信息更新了我的答案 – 2010-09-20 21:04:24