简体   繁体   English

在Azure中发布时Web应用程序行为不同

[英]Web Application behaviour different when publishing in Azure

I have created a web application in which I am calling c# method. 我创建了一个Web应用程序,我在其中调用c#方法。 In the c# method, I return an object that contains a value like 1, 2 , 3. When I run the application in the localhost, I get the exact value of the object. 在c#方法中,我返回一个包含类似1,2,3的值的对象。当我在localhost中运行应用程序时,我得到了对象的确切值。 However, when I publish this application in AZURE without making any change. 但是,当我在AZURE中发布此应用程序而不做任何更改时。 I don't get the value like 1, 2, 3 but instead I get the value System.Object. 我没有得到像1,2,3这样的值,而是得到值System.Object。 I don't understand this strange behaviour. 我不明白这种奇怪的行为。 Kindly assist me. 请帮助我。 Here is my code: 这是我的代码:

$('#btn').click(function(){
    PageMethods.SaveNDig(obj, OnComplete);
});

C# Method: C#方法:

[WebMethod]
public static string SaveNDig(Object obj)//string CourseName, string CourseCategoryURL, string CourseCategoryName, string CourseInfo, string PassPercentage, string TextBooks, string GradingSchemes
{

    object result = database.ExecuteScalar("select userid from EUser where username ='" + username + "'");
    return result;
}

public static object ExecuteScalar(string query)
{
    object obj = new object();
    try
    {
        con = InitializeConnection();
        cmd = new SqlCommand(query, con);
        con.Open();
        obj = cmd.ExecuteScalar();
    }
    catch (Exception ex) { }
    finally
    {
        if (con.State == System.Data.ConnectionState.Open)
        {
            con.Close();
        }
    }
    return obj != null ? obj : null;
}

ExecuteScalar returns an Object. ExecuteScalar返回一个Object。 I have seen this issue that you are referring to -- and in fact, came across your question looking for issues with Azure and ExecuteScalar. 我已经看到了你所指的这个问题 - 事实上,遇到了你的问题,寻找Azure和ExecuteScalar的问题。 ExecuteScalar is documented to return the first column in the first row of the returned object. 记录ExecuteScalar以返回返回对象的第一行中的第一列。

FYI, we use Entity Framework and the DB in question resides locally and in the cloud. 仅供参考,我们使用实体框架,有问题的数据库驻留在本地和云端。 Locally, my inserts work find using ExecuteScalar, but the Object returned is useless. 在本地,我的插入工作使用ExecuteScalar查找,但返回的Object是无用的。 Attempting to cast it throws an InvalidCast exception. 尝试强制转换会抛出InvalidCast异常。

I have started replacing ExecuteScalar with ExecuteNonQuery and that works fine so far. 我已经开始用ExecuteNonQuery替换ExecuteScalar,到目前为止工作正常。

Here is an article that I found most helpful in troubleshooting my Azure based DB access… 这篇文章我发现最有助于解决基于Azure的数据库访问问题...

https://www.simple-talk.com/blogs/2012/05/31/3-tips-for-sql-azure-connection-perfection https://www.simple-talk.com/blogs/2012/05/31/3-tips-for-sql-azure-connection-perfection

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM