SQL Data Tools 2012中的表值函数将不会发布

时间:2013-12-21 12:25:46

标签: c# sql sql-server visual-studio-2012

我想用SQL数据工具创建表值函数,但不会发布。 我有一个包含列的数据库:

Id(bigint), Voornaam (Nchar(50)), Naam (Nchar(50)), AantalPintjes (bigint)

我的代码将成功构建,但是当我想发布时,我收到错误:

  

“在数据库'bier上执行发布脚本':正在执行批处理时发生错误。

在发布的SQL中,我收到了一个脚本执行错误:

IF EXISTS (SELECT TOP 1 1
    FROM [dbo].[tbl_BierDrinkers])
RAISERROR (N'Rows were detected. The schema update is terminating because data loss might occur.', 16, 127)
    WITH NOWAIT;

这是我的C#代码:

public class Bierdrinkers
{
    public SqlInt64 Id { get; set; }
    public SqlString Naam { get; set; }
    public SqlString Voornaam { get; set; }
    public SqlInt64 AantalPintjes { get; set; }

    public Bierdrinkers()
    {

    }

    public override string ToString()
    {
        return Convert.ToString(Naam) + " : (aantal pintjes: " + Convert.ToInt64(AantalPintjes) + " )";
    }


    [SqlFunction(DataAccess = DataAccessKind.Read,FillRowMethodName = "VentileerRijen", TableDefinition = "Id bigint,Naam nchar(50), Voornaam nchar(10), AantalPintjes bigint")]
    public static IEnumerable OphalenData()
    {
        List<Bierdrinkers> res = new List<Bierdrinkers>();
       /* res.Add(new Bierdrinkers() { AantalPintjes = 1, Id = 1, Naam = "a", Voornaam = "b" });
         return res;*/


        using (SqlConnection connection = new SqlConnection("context connection=true"))
        {
            connection.Open();
            // Use the connection

            string SQL = "Select * from tbl_BierDrinkers";
            SqlCommand sqlcomm = new SqlCommand(SQL, connection);

            SqlDataReader datareader = sqlcomm.ExecuteReader();
            while (datareader.Read())
            {
                Bierdrinkers bd = new Bierdrinkers();
                bd.Id = Convert.ToInt32(datareader["Id"]);
                bd.Naam = datareader["Naam"].ToString();
                bd.Voornaam = datareader["Voornaam"].ToString();
                bd.AantalPintjes = Convert.ToInt32(datareader["AantalPintjes"]); ;
                res.Add(bd);
                Console.WriteLine(bd);
            }
            return res;
        }
    }

    public static void VentileerRijen(object obd, out SqlInt64 Id, out SqlString Naam, out SqlString Voornaam, out SqlInt64 AantalPintjes)
    {
        Bierdrinkers bd = obd as Bierdrinkers;
        Id = bd.Id;
        Naam = bd.Naam;
        Voornaam = bd.Voornaam;
        AantalPintjes = bd.AantalPintjes;
    }
}

我也尝试了一个启动脚本,但没有区别:

use Bier;
select * from OphalenData();

0 个答案:

没有答案