Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对正确数据库的Dapper存储过程调用_C#_Asp.net_Dapper - Fatal编程技术网

C# 对正确数据库的Dapper存储过程调用

C# 对正确数据库的Dapper存储过程调用,c#,asp.net,dapper,C#,Asp.net,Dapper,我有以下单一数据库结构: Server | Database + Tables + Programmability(stored procedures) 其中,我使用以下方法使用Dapper进行存储过程调用: public List<Events> GetEvents() { using (var connection = new SqlConnection(SQLSettings.GetConnectionString())) {

我有以下单一数据库结构:

Server
  |
  Database
    + Tables
    + Programmability(stored procedures)
其中,我使用以下方法使用Dapper进行存储过程调用:

public List<Events> GetEvents()
{
    using (var connection = new SqlConnection(SQLSettings.GetConnectionString()))
    {
        return connection.Query<Events>("GetEvents", commandType: CommandType.StoredProcedure).ToList();
    }

}

我的问题是,我需要如何修改我的方法以确保它命中存储过程所在的正确数据库?

您使用正确的连接字符串来确保它

using (var connection = new SqlConnection("Connection string of the first db"))
{
    return connection.Query<Events>("GetEvents", commandType: CommandType.StoredProcedure).ToList();
}

using (var connection = new SqlConnection("Connection string of the second db"))
{
    return connection.Query<Events>("GetEvents", commandType: CommandType.StoredProcedure).ToList();
}
使用(var-connection=new-SqlConnection(“第一个db的连接字符串”))
{
返回connection.Query(“GetEvents”,commandType:commandType.StoredProcedure.ToList();
}
使用(var connection=newsqlconnection(“第二个db的连接字符串”))
{
返回connection.Query(“GetEvents”,commandType:commandType.StoredProcedure.ToList();
}

您正在确保使用正确的连接字符串

using (var connection = new SqlConnection("Connection string of the first db"))
{
    return connection.Query<Events>("GetEvents", commandType: CommandType.StoredProcedure).ToList();
}

using (var connection = new SqlConnection("Connection string of the second db"))
{
    return connection.Query<Events>("GetEvents", commandType: CommandType.StoredProcedure).ToList();
}
使用(var-connection=new-SqlConnection(“第一个db的连接字符串”))
{
返回connection.Query(“GetEvents”,commandType:commandType.StoredProcedure.ToList();
}
使用(var connection=newsqlconnection(“第二个db的连接字符串”))
{
返回connection.Query(“GetEvents”,commandType:commandType.StoredProcedure.ToList();
}

假设您知道在哪个DB(1或2)中查找SP,请使用以下任一选项:

using (var connection = new SqlConnection(SQLSettings.GetConnectionString1()))
{ ... }


假设您知道要在哪个DB(1或2)中找到SP,请使用以下任一选项:

using (var connection = new SqlConnection(SQLSettings.GetConnectionString1()))
{ ... }


它使用的数据库是基于连接字符串的。我认为它很简单。感谢大家的快速回复。它使用的数据库是基于连接字符串的。我觉得这很简单。谢谢大家的快速回复。