locked
How to run procedure exist on database different from current database I connected and another database on same server ? RRS feed

  • Question

  • User696604810 posted

    problem

    How to run procedure exist on database different from current database I connected ?

    I work on csharp ado.net technology I need to run stored procedure exist on another database different from current and not exist on current database dbtest but it exist on databae dbworking

    function below return data table 

    this function pass value exist on parameter name to stored procedure name then run it and display result

    my current database is dbtest

    I have database on same server is name dbworking have stored procedure dbo.GetBooksData

    so i pass procedure as following dbworking.dbo.GetBooksData

    all procedure on current database not have any issue it working

    but suppose i pass procedure name starting by another database on same server 

    can i run and execute this procedure name  dbworking.dbo.GetBooksData or what

    if can How i do that please ?

    onnection 
    "Data Source=192.168.77.70;Initial Catalog=DbTest;Integrated Security=False;Persist Security Info=False;User ID=sa;Password=321;
    public DataTable GetSpByRevisionId(string ParameterNameValue, string SpName)
            {
                System.Data.SqlClient.SqlConnection sqlCon = new SqlConnection(_connectionString);
                sqlCon.Open();
                using (SqlCommand cmd = new SqlCommand(SpName, sqlCon))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@ParamterName", SqlDbType.Int).Value = ParameterName;
    
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    sqlCon.Close();
                    return dt;
                }
            }
    when run function
    GetSpByRevisionId("1777","dbworking.dbo.GetBooksData")

    so if run function above it will run or not 

    if can how to run procedure on database different from current database ?

    Saturday, May 9, 2020 4:44 AM

All replies

  • User475983607 posted

    There's no restriction on the number of databases a application s connects to.

    Do you have an actual problem or error? 

    Saturday, May 9, 2020 11:22 AM