【问题标题】:SQLCommand (type or name could not found. are you missing any directives )?SQLCommand(找不到类型或名称。您是否缺少任何指令)?
【发布时间】:2011-09-19 16:23:35
【问题描述】:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;


namespace WcfService1
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {
        string Connection = "server=SHUMAILA-PC;  database=kse; Connect Timeout=10000";
        [WebMethod]
        public void SQLconn()
        {
            SqlConnection DataConnection = new SqlConnection(Connection);
            // the string with T-SQL statement, pay attention: no semicolon at the end of //the statement
            string Command = "INSERT INTO login VALUES (shumaila,mypassword)";
            // create the SQLCommand instance
            SQLCommand DataCommand = new SqlCommand(Command, DataConnection);
            // open the connection with our database
            DataCommand.Connection.Open();
            // execute the statement and return the number of affected rows
            int i = DataCommand.ExecuteNonQuery();
            //close the connection
            DataCommand.Connection.Close();  
        }

    }
}

我正在使用 system.data.SqlClient 指令,但它仍然给我这个错误。我该怎么办?

【问题讨论】:

    标签: asp.net web-services sql-server-2005


    【解决方案1】:

    你有一个错字:

    SqlCommand DataCommand = new SqlCommand(Command, DataConnection);
    

    SqlCommand 代替 SQLCommand

    【讨论】:

    • 用户 '' 登录失败。该用户未与受信任的 SQL Server 连接关联。
    • @shumaila 这是一个不同的问题 - 查看connectionstrings.com 以找到适合您的连接字符串的正确格式。
    猜你喜欢
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 2020-11-28
    • 2015-06-12
    • 2015-04-19
    • 2013-05-22
    相关资源
    最近更新 更多