to change owner of object/Stored Procedure
exec sp_changeobjectowner 'objectname','username'
for example
exec sp_changeobjectowner 'proc_getallrecords','dbo'
Friday, October 17, 2008
Grant Execute Permission to User in Database:Sql Servers
---Stored Procedure to grant execute permission to user on all stored procedures
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spGrantExectoAllStoredProcs] @user sysname
AS
/
SET NOCOUNT ON
DECLARE @CMD1 varchar(8000)
DECLARE @MAXOID int
DECLARE @OwnerName varchar(128)
DECLARE @ObjectName varchar(128)
CREATE TABLE #StoredProcedures
(OID int IDENTITY (1,1),
StoredProcOwner varchar(128) NOT NULL,
StoredProcName varchar(128) NOT NULL)
INSERT INTO #StoredProcedures (StoredProcOwner, StoredProcName)
SELECT u.[Name], o.[Name]
FROM dbo.sysobjects o
INNER JOIN dbo.sysusers u
ON o.uid = u.uid
WHERE o.Type = 'P'
AND o.[Name] NOT LIKE 'dt_%'
SELECT @MAXOID = MAX(OID) FROM #StoredProcedures
WHILE @MAXOID > 0
BEGIN
SELECT @OwnerName = StoredProcOwner,
@ObjectName = StoredProcName
FROM #StoredProcedures
WHERE OID = @MAXOID
SELECT @CMD1 = 'GRANT EXEC ON ' + '[' + @OwnerName + ']' + '.' + '[' + @ObjectName + ']' + ' TO ' + @user
EXEC(@CMD1)
SET @MAXOID = @MAXOID - 1
END
DROP TABLE #StoredProcedures
SET NOCOUNT OFF
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spGrantExectoAllStoredProcs] @user sysname
AS
/
SET NOCOUNT ON
DECLARE @CMD1 varchar(8000)
DECLARE @MAXOID int
DECLARE @OwnerName varchar(128)
DECLARE @ObjectName varchar(128)
CREATE TABLE #StoredProcedures
(OID int IDENTITY (1,1),
StoredProcOwner varchar(128) NOT NULL,
StoredProcName varchar(128) NOT NULL)
INSERT INTO #StoredProcedures (StoredProcOwner, StoredProcName)
SELECT u.[Name], o.[Name]
FROM dbo.sysobjects o
INNER JOIN dbo.sysusers u
ON o.uid = u.uid
WHERE o.Type = 'P'
AND o.[Name] NOT LIKE 'dt_%'
SELECT @MAXOID = MAX(OID) FROM #StoredProcedures
WHILE @MAXOID > 0
BEGIN
SELECT @OwnerName = StoredProcOwner,
@ObjectName = StoredProcName
FROM #StoredProcedures
WHERE OID = @MAXOID
SELECT @CMD1 = 'GRANT EXEC ON ' + '[' + @OwnerName + ']' + '.' + '[' + @ObjectName + ']' + ' TO ' + @user
EXEC(@CMD1)
SET @MAXOID = @MAXOID - 1
END
DROP TABLE #StoredProcedures
SET NOCOUNT OFF
Monday, October 13, 2008
code for 301 redirect pages with querystring using asp.net/c#
if you have a page with query string and you want to redirect it using asp.net please check the code below..
string c_absUri = Request.Url.DnsSafeHost;
string c_absPath = Request.Url.AbsolutePath;
//c_absPath = "/test.aspx";
string c_queryString = Request.QueryString.ToString().Length > 0 ? Request.QueryString.ToString() : String.Empty;
if (c_queryString.Contains("sname=")) //where sname is querystring
{
Int32 Countqry = 0;
Int32 qrylength = 0;
qrylength = c_queryString.Length;
Countqry = c_queryString.LastIndexOf("=");
Int32 rem = qrylength - Countqry;
string sname = c_queryString.Substring(Countqry + 1, rem - 1);
sname = sname.Replace("*", "&");
sname = sname.Replace("+", " ");
string newUrl = "http://www.abc.com" + c_absPath;
HttpContext context = HttpContext.Current;
context.Response.Status = "301 Moved Permanently";
context.Response.StatusCode = 301;
context.Response.AddHeader("Location", newUrl);
Response.Redirect(newUrl);
}
string c_absUri = Request.Url.DnsSafeHost;
string c_absPath = Request.Url.AbsolutePath;
//c_absPath = "/test.aspx";
string c_queryString = Request.QueryString.ToString().Length > 0 ? Request.QueryString.ToString() : String.Empty;
if (c_queryString.Contains("sname=")) //where sname is querystring
{
Int32 Countqry = 0;
Int32 qrylength = 0;
qrylength = c_queryString.Length;
Countqry = c_queryString.LastIndexOf("=");
Int32 rem = qrylength - Countqry;
string sname = c_queryString.Substring(Countqry + 1, rem - 1);
sname = sname.Replace("*", "&");
sname = sname.Replace("+", " ");
string newUrl = "http://www.abc.com" + c_absPath;
HttpContext context = HttpContext.Current;
context.Response.Status = "301 Moved Permanently";
context.Response.StatusCode = 301;
context.Response.AddHeader("Location", newUrl);
Response.Redirect(newUrl);
}
Code for 301 Redirect using c#/ASP.NET
if you want to do a 301 permanent redirect using asp.net and c# copy and paste the code in ur global.asax file.
protected void Application_BeginRequest(object sender, EventArgs e)
{
string newpath = "";
string newpath1 = "";
string sOldPath = HttpContext.Current.Request.Url.ToString();
sOldPath =sOldPath.Substring(sOldPath.LastIndexOf("/")+1);
//
if(sOldPath=="Online.aspx")
{
newpath = "http://www.the.com/online-degree.aspx";
HttpApplication app = sender as HttpApplication;
app.Context.Response.RedirectLocation = newpath.ToString();
app.Context.Response.StatusCode = 301;
app.Context.Response.End();
}}
if you have any questions on doing a 301 redirect please let me know.
protected void Application_BeginRequest(object sender, EventArgs e)
{
string newpath = "";
string newpath1 = "";
string sOldPath = HttpContext.Current.Request.Url.ToString();
sOldPath =sOldPath.Substring(sOldPath.LastIndexOf("/")+1);
//
if(sOldPath=="Online.aspx")
{
newpath = "http://www.the.com/online-degree.aspx";
HttpApplication app = sender as HttpApplication;
app.Context.Response.RedirectLocation = newpath.ToString();
app.Context.Response.StatusCode = 301;
app.Context.Response.End();
}}
if you have any questions on doing a 301 redirect please let me know.
Labels:
301 redirect,
301 redirect using asp.net
Subscribe to:
Posts (Atom)