Quantcast
Channel: SQL Service Broker forum
Viewing all articles
Browse latest Browse all 461

sqldependency not working

$
0
0

so this is what i have done with no success

ran this

GRANT CREATE PROCEDURE to [IIS APPPOOL\AO] 
GRANT CREATE QUEUE to [IIS APPPOOL\AO]
GRANT CREATE SERVICE to [IIS APPPOOL\AO]

ran this

USE [DIRECTORYDB.MDF];
CREATE QUEUE depQue;
CREATE SERVICE depQue ON QUEUE depQue ([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]);
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO [IIS APPPOOL\AO];
ALTER DATABASE [DIRECTORY.MDF] SET ENABLE_BROKER;

gave me this error but still created depQue

User does not have permission to alter database 'DIRECTORY.MDF', the database does not exist, or the database is not in a state that allows access checks.

and wrote this code

 SqlClientPermission permission =
       new SqlClientPermission(
       PermissionState.Unrestricted);
        try
        {
            permission.Demand();

        }
        catch (System.Exception)
        {
            Response.Write("<script>alert('" + "no permission" + "')</script>");
        }
        string connectionString = "Data Source =.\\SQLEXPRESS; Initial Catalog = DIRECTORYDB.MDF;  Integrated Security = True";
        SqlDependency.Start(connectionString, "depQue");

        using (SqlConnection con = new SqlConnection(connectionString))
        {
            con.Open();
            using (SqlCommand command = new SqlCommand("SELECT First_Name FROM [Table]", con))
            {
                command.Notification = null;
                // Create a dependency and associate it with the SqlCommand.
                SqlDependency dependency = new SqlDependency(command);
                // Maintain the refence in a class member.

                // Subscribe to the SqlDependency event.
                dependency.OnChange += new OnChangeEventHandler(OnDependencyChange);

                // Execute the command.
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    // Process the DataReader.
                }
            }
        }
        //GridView1.Columns[1].Visible = false;
        /*
        if (!this.IsPostBack)
        {
            this.BindGrid();
        }
        */
    }
    void OnDependencyChange(object sender, SqlNotificationEventArgs e)
    {
        // Handle the event (for example, invalidate this cache entry).
        Response.Write("<script>alert('" + "test" + "')</script>");
    }

please help, 

thank you!


Viewing all articles
Browse latest Browse all 461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>