WCF数据库错误 [英] WCF-Database error
问题描述
这是我的运行时错误:
程序失败这一行:
conn.Open();
conn.Open();
这是我的代码:
public int InsertSchedule(Schedule item)
{
try
{
comm.CommandText = "INSERT INTO Other VALUES(@Id,@Opponent,@Site,@Team,@Time)";
comm.Parameters.AddWithValue("Id", item.Id);
comm.Parameters.AddWithValue("Opponent", item.Opponent);
comm.Parameters.AddWithValue("Site", item.Site);
comm.Parameters.AddWithValue("Team", item.Team);
comm.Parameters.AddWithValue("Time", item.date);
comm.Parameters.AddWithValue("Tournament Name", item.TournamentName);
comm.CommandType = CommandType.Text;
conn.Open();
return comm.ExecuteNonQuery();
}
catch(Exception ex)
{
throw;
}
finally
{
if(conn != null)
{
conn.Close();
}
}
return 1;
}
void ConnectToDb()
{
connStringBuilder = new SqlConnectionStringBuilder();
connStringBuilder.DataSource = "USAyou";
connStringBuilder.InitialCatalog = "Wrestling";
connStringBuilder.Encrypt = true;
connStringBuilder.ConnectTimeout = 30;
connStringBuilder.AsynchronousProcessing = true;
connStringBuilder.MultipleActiveResultSets = true;
connStringBuilder.IntegratedSecurity = true;
conn = new SqlConnection(connStringBuilder.ToString());
comm = conn.CreateCommand();
}
我正在使用我的计算机名称作为DataSource,我尝试过"localhost"和
I am using my computer name for the DataSource and i have tried "localhost"
但这也不起作用
我也尝试过使用:
DataSource = @" C:\ Users \ dan \Documents\Visual Studio 2013 \Projects\Bailey Service\Bailey Service\App_Data \ Wrestling.mdf";
DataSource = @"C:\Users\dan\Documents\Visual Studio 2013\Projects\Bailey Service\Bailey Service\App_Data\Wrestling.mdf";
但它仍然无效
but it still does not work
推荐答案
好的我看了这个:
ok I looked at this :
连接测试工作 但C#代码仍然给我这个错误。
the connection test works but the C# code still gives me that error.
我也试过&conbspStringBuilder.DataSource ="(LocalDB)\ v11.0"
also, I tried connStringBuilder.DataSource = "(LocalDB)\v11.0"
这篇关于WCF数据库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!