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

  • Thread starter Thread starter engahmedbarbary
  • Start date Start date
E

engahmedbarbary

Guest
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 ?


connection

"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 ?

Continue reading...
 
Back
Top