小编Use*_*384的帖子

实体框架基础提供程序在Open上失败

下面是我的连接字符串:

的connectionString ="元数据= RES://*/EDMX.Test.csdl | RES://*/EDMX.Test.ssdl | RES://*/EDMX.Test.msl;提供商= System.Data.SqlClient的;提供者connection string ="Data Source = home_computer; Initial Catalog = db_Test; Persist Security Info = True; User ID = testUser; Password = $ 1234; MultipleActiveResultSets = True""

这是程序卡住的代码:

EDMX.TestingEntity context = new EDMX.TestingEntity();

var query = from t in context.User
            where t.UserName == _userName
            select t;
Run Code Online (Sandbox Code Playgroud)

运行上面的代码后,我检查变量查询并发现异常

底层提供程序在Open上失败.

我检查过:

  1. 服务器和计算机之间的连接正常
  2. 我可以使用用户名testuser和密码$ 1234登录数据库
  3. 我已检查数据库(SQL Server)中的安全设置是否已授予testUser权限

为什么会发生这种异常?我正在使用.net 4.5


添加:

我再次尝试,查看内部异常,它是:建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称是否正确,以及SQL Server是否配置为允许远程连接.(提供者:命名管道提供程序,错误:40 - 无法打开与SQL Server的连接)

我知道这可能是一个网络问题,但我关闭了服务器和我的电脑的防火墙,并再次尝试,但仍然没有成功..


刚刚将连接字符串复制到一个程序来测试这个连接,它运行良好..


我只是回滚所有更改并再次测试并且它有效

c# entity-framework

33
推荐指数
5
解决办法
24万
查看次数

C#使用Sendkey函数将密钥发送到另一个应用程序

我想将一个特定的密钥(例如k)发送到另一个名为notepad的程序,下面是我使用的代码:

void sendkey ()
{
    [DllImport ("User32.dll")]
    static extern int SetForegroundWindow(IntPtr point);

    Process p = Process.GetProcessesByName("notepad")[0];
    IntPtr pointer = p.Handle;
    SetForegroundWindow(pointer);
    SendKeys.Send("k");
}
Run Code Online (Sandbox Code Playgroud)

但代码不起作用,代码有什么问题?

编辑:如果没有记事本作为活动窗口,我可以将"K"发送到记事本吗?(例如,活动窗口="Google Chrome",记事本位于背景中,这意味着将密钥发送到后台应用程序)

c# sendkeys

25
推荐指数
1
解决办法
10万
查看次数

未捕获的TypeError:无法使用'in'运算符在JSON字符串中搜索''

我在我的网站上使用了令牌输入,这是我如何初始化令牌输入:

$(document).ready(function () {           
    var populateValue = document.getElementById('<%= hiddentokenPrePopulate.ClientID%>').value
    $("#<%= tokenEmployee.ClientID%>").tokenInput("../Employee/getEmployeeDetails.ashx", {
        deleteText: "X",
        theme: "facebook",
        preventDuplicates: true,
        tokenDelimiter: ";",
        minChars: 3,
        tokenLimit: 1,
        prePopulate: populateValue
    });
});
Run Code Online (Sandbox Code Playgroud)

脚本停留在这一行:

 prePopulate: populateValue
Run Code Online (Sandbox Code Playgroud)

当我删除这一行时,不会有任何javascript错误,但我需要这个,因为我需要预先填充令牌输入.该populateValue方法是:

[{
    "id": "11566",
    "name": "Smith - White"
}]
Run Code Online (Sandbox Code Playgroud)

有一个javascript错误:

未捕获的TypeError:不能使用'in'运算符在[{"id":"11566","name":"Smith - White"}中搜索'47'

我该如何解决这个错误?

javascript asp.net jquery json jquery-tokeninput

16
推荐指数
1
解决办法
8万
查看次数

通过Entity Framework将表值类型传递给SQL Server存储过程

我在SQL Server中创建了一个用户定义的表类型:

CREATE TYPE dbo.TestType AS TABLE 
(
    ColumnA int,
    ColumnB nvarchar(500)
)
Run Code Online (Sandbox Code Playgroud)

我正在使用存储过程将记录插入数据库:

create procedure [dbo].[sp_Test_CustomType]
   @testing TestType READONLY
as
    insert into [dbo].[myTable]
        select ColumnA, ColumnB 
        from @testing
Run Code Online (Sandbox Code Playgroud)

我想使用EF来执行这个存储过程,但问题是:如何将用户定义的表传递给存储过程?

我尝试将存储过程添加到模型中,但我无法在更新的上下文中找到所需的存储过程.

我要做的是对表执行批量插入,这是我目前使用的方法:

List<items> itemToInsertToDB = //fetchItems;

foreach(items i in itemToInsertToDB)
{
     context.sp_InsertToTable(i.ColumnA, i.ColumnB)
}
Run Code Online (Sandbox Code Playgroud)

目前,我使用foreach循环遍历列表以将项目插入到DB,但如果列表中有很多项目,那么就会出现性能问题,因此,我正在考虑将列表传递给存储过程并且插入内部.

那么如何解决这个问题呢?或者有更好的方法吗?

c# sql sql-server stored-procedures entity-framework

13
推荐指数
1
解决办法
1万
查看次数

DataTables无法读取未定义的属性"长度"

下面是文档就绪功能

Script type="text/javascript" charset="utf-8">
    $(document).ready(function () {
        $('#example').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "GetUser.ashx",
            "sServerMethod": "POST",
            "sAjaxDataProp" : "",
            "aoColumnDefs": [ {
            "aTargets": [ 0 ],
            "mData": "download_link",
            "mRender": function ( data, type, full ) {
               return '<a href="/UserDetail.aspx?ID='+data+'">Detail</a>';
             }
           } ],
            "aoColumns": [
                { "mData": "LoginId" },
                { "mData": "Name" },
                { "mData": "CreatedDate" }
            ]
        });
Run Code Online (Sandbox Code Playgroud)

以下是来自服务器的响应(GetUser.ashx)

[
    {
        "UserId": "1",
        "LoginId": "white.smith",
        "Activated": "Y",
        "Name": "Test Account",
        "LastName": "Liu",
        "Email": "white.smith@logical.com",
        "CreatedDate": "1/21/2014 12:03:00 PM",
        "EntityState": "2", …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net jquery datatables jquery-datatables

9
推荐指数
2
解决办法
5万
查看次数

System.Web.Services.Protocols.SoapException:服务器无法识别HTTP标头SOAPAction的值:

当我尝试在Web服务上调用方法时,会发生异常:

System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://localhost:53460/3Development/MyWebService.asmx/GetBasePath.
   at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
   at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
   at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
Run Code Online (Sandbox Code Playgroud)

Web服务的命名空间:

[WebService(Namespace = "http://internaltest.temp.us/MyWebService.asmx")]
Run Code Online (Sandbox Code Playgroud)

我做了一些研究,发现这个异常流程是因为项目中引用的Web服务的命名空间与服务器Web服务的命名空间不同,但我尝试删除Web引用并在项目中再次添加它,但结果仍然是相同.

我的情况类似于下面的文章:

http://bluebones.net/2003/07/server-did-not-recognize-http-header-soapaction/

来自文章:

所以基本上Web服务从http://foo.com/servicename 移到了http://bar.com/servicename,但Web服务的"命名空间"保持为http://foo.com/servicename,因为没有人改变了

问题是:

如何更改Web引用的命名空间?

c# asp.net soap web-services exception

8
推荐指数
1
解决办法
3万
查看次数

如何将数组中的第n项作为数组中的第z项?

我创建了一个这样的数组:

string[] test = new string[]{"apple", "banana", "tomato", "pineapple", "grapes"};
Run Code Online (Sandbox Code Playgroud)

现在,我想把数组中的第2,第3和第4项加在一起,目前我正在使用这段代码:

string result = "";
for(int i = 1; i < 4; i++)
{
    result += test[i] + " ";
}
Run Code Online (Sandbox Code Playgroud)

所以结果会是这样banana tomato pineapple,这很好.

我想问一下是否有标准或更好的方法来实现这一目标?

c# arrays

7
推荐指数
2
解决办法
693
查看次数

Crystal报表文档加载挂起

每当程序到达以下代码时,程序就会挂起

protected void InitCrystalReport(String _reportUrl)
{
    myReportDocument.Load(_reportUrl);
}
Run Code Online (Sandbox Code Playgroud)

这种情况只发生在我将网页放在IIS(另一台服务器)上,但是当我在Visual Studio上运行应用程序(调试模式)时它不存在.我还使用进程监视器来监视进程以查看文件是否被拒绝访问.

我在下面尝试过Web Server,但它们都不起作用:

  1. 将应用程序池更改为.NET Classic
  2. 重新启动打印机假脱机程序

编辑
我重新启动了服务器,现在一切正常

c# crystal-reports crystal-reports-2008

5
推荐指数
1
解决办法
1429
查看次数

按列名字符串对列表进行排序

假设我有一个这样的课程

public class model
{
    public int id{get;set;}
    public string name{get;set;}
    public string department{get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我有一个类型模型列表

List<model> modelList = List<model>();
Run Code Online (Sandbox Code Playgroud)

如何使用排序方向对列名进行排序?

我试过的方法:

public List<model> sortModelList(string columnName, SortDirection direction)
{
   //Method 1:
   //The below code was unable to sort by column and unable to set the sort direction
   return modelList.Sort();

   //Method 2:
   //The below code was unable to sort by the columnName parameter and unable to set the sort direction
   return modelList.OrderBy(a=>a.name)

  //What I can do in order to sort the …
Run Code Online (Sandbox Code Playgroud)

c# sorting list

5
推荐指数
2
解决办法
8831
查看次数

MYSQL Left join 在索引列上非常慢

以下是4张表的表结构:

日历:

CREATE TABLE `calender` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `HospitalID` int(11) NOT NULL,
  `ColorCode` int(11) DEFAULT NULL,
  `RecurrID` int(11) NOT NULL,
  `IsActive` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`ID`),
  UNIQUE KEY `ID_UNIQUE` (`ID`),
  KEY `idxHospital` (`ID`,`StaffID`,`HospitalID`,`ColorCode`,`RecurrID`,`IsActive`)
) ENGINE=InnoDB AUTO_INCREMENT=4638 DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)

日历参加者:

CREATE TABLE `calenderattendee` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `CalenderID` int(11) NOT NULL,
  `StaffID` int(11) NOT NULL,
  `IsActive` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`ID`),
  KEY `idxCalStaffID` (`StaffID`,`CalenderID`)
) ENGINE=InnoDB AUTO_INCREMENT=20436 DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)

呼叫计划员工: …

mysql sql

5
推荐指数
1
解决办法
4372
查看次数