Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[2005] CLR with execute as 'myUser' / C#

1 réponse
Avatar
CrazyMasterMC
Salut,

J'ai besoin de déployer une procédure externe créée en C# à l'aide du CLR.

Tout fonctionne bien mais je suis obligé de la déployer à la main (et c'est
vraiment lourd) car nous n'avons pas trouvé comment ajouter l'option T-SQL
with execute as 'myUser' à notre proc compilée.

Voici le code :

public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void AnnuaireFind(SqlInt32 intBuId, SqlInt32 intSSId,
SqlInt32 intREId, SqlInt32 intCOId, SqlString strLangueId, SqlInt32 intJobId,
SqlString strSearch)
{
strLangueId = (SqlString)strLangueId.ToString().ToLower();
strSearch = (SqlString)Regex.Replace((string)strSearch, @"(\')",
"''");
StringBuilder oSBSQL = new StringBuilder();
oSBSQL.Append("SELECT DISTINCT ");
oSBSQL.Append("VAnnu.AnnuaireId, ");
oSBSQL.Append("VAnnu.AnnuaireLastName, ");
oSBSQL.Append("VAnnu.AnnuaireFirstName, ");
oSBSQL.Append("VAnnu.AnnuaireMail, ");
oSBSQL.Append("VAnnu.AnnuairePhone, ");
oSBSQL.Append("Vannu.JobTitle, ");
oSBSQL.Append("VAnnu.LocationName ");
oSBSQL.Append("FROM ");
oSBSQL.Append("SchemaWeb.ViewAnnuaireUserList AS VAnnu ");
StringBuilder oSBClause = new StringBuilder(" WHERE ");
oSBClause.Append("(VAnnu.AnnuaireId = VAnnu.AnnuaireId) ");

if (intBuId > 0)
{
oSBClause.Append(" AND (VAnnu.BuId = " + intBuId.ToString() + ")
");
}

if (intSSId > 0)
{
oSBClause.Append(" AND (VAnnu.FunctionId = " +
intSSId.ToString() + ") ");
}
if (intREId > 0)
{
oSBClause.Append(" AND (VAnnu.RegionId = " + intREId.ToString()
+ ") ");
}
if (intCOId > 0)
{
oSBClause.Append(" AND (VAnnu.ContractId = " +
intCOId.ToString() + ") ");
}
if (intJobId > 0)
{
oSBClause.Append(" AND (VAnnu.JobId = " + intJobId.ToString() +
") ");
}
if (strSearch != "")
{
oSBClause.Append(" AND LOWER(");
oSBClause.Append(" isnull(VAnnu.AnnuaireLastName + ' ','') +");
oSBClause.Append(" isnull(VAnnu.AnnuaireFirstName + ' ','') +");
oSBClause.Append(" isnull(VAnnu.AnnuaireMail + ' ','') +");
oSBClause.Append(" isnull(VAnnu.JobTitle + ' ','') +");
oSBClause.Append(" isnull(VAnnu.LocationName + ' ','')");
oSBClause.Append(" ) like lower('%");
oSBClause.Append((string)strSearch);
oSBClause.Append("%') ");
}
oSBSQL.Append(oSBClause.ToString());
using (SqlConnection oConn = new SqlConnection("context
connection=true"))
{
SqlCommand oCmd;
oConn.Open();
oCmd = new SqlCommand(oSBSQL.ToString(), oConn);
SqlContext.Pipe.ExecuteAndSend(oCmd);
oConn.Close();
}
}
};
Quelqu'un saurait me dire s'il est possible d'ajouter cette option ? Si oui
avec quelle syntaxe ?

D'avance merci

Laurent Jordi
http://www.ezlogic.mc

1 réponse

Avatar
Sean McCown
Oui, c'est parse que cet option n'exist pas dans le CLR.
Le meme pour 'with encryption'.


--
Watch my free SQL Server Tutorials at:
<a href="http://MidnightDBA.ITBookworm.com"
target="_new">http://MidnightDBA.ITBookworm.com </a>

Read my book reviews at:
http://www.ITBookworm.com

Blog Author of:
Database Underground -- http://weblog.infoworld.com/dbunderground/
DBA Rant – http://dbarant.blogspot.com




"CrazyMasterMC" wrote:

Salut,

J'ai besoin de déployer une procédure externe créée en C# à l'aide du CLR.

Tout fonctionne bien mais je suis obligé de la déployer à la main (et c'est
vraiment lourd) car nous n'avons pas trouvé comment ajouter l'option T-SQL
with execute as 'myUser' à notre proc compilée.

Voici le code :

public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void AnnuaireFind(SqlInt32 intBuId, SqlInt32 intSSId,
SqlInt32 intREId, SqlInt32 intCOId, SqlString strLangueId, SqlInt32 intJobId,
SqlString strSearch)
{
strLangueId = (SqlString)strLangueId.ToString().ToLower();
strSearch = (SqlString)Regex.Replace((string)strSearch, @"(')",
"''");
StringBuilder oSBSQL = new StringBuilder();
oSBSQL.Append("SELECT DISTINCT ");
oSBSQL.Append("VAnnu.AnnuaireId, ");
oSBSQL.Append("VAnnu.AnnuaireLastName, ");
oSBSQL.Append("VAnnu.AnnuaireFirstName, ");
oSBSQL.Append("VAnnu.AnnuaireMail, ");
oSBSQL.Append("VAnnu.AnnuairePhone, ");
oSBSQL.Append("Vannu.JobTitle, ");
oSBSQL.Append("VAnnu.LocationName ");
oSBSQL.Append("FROM ");
oSBSQL.Append("SchemaWeb.ViewAnnuaireUserList AS VAnnu ");
StringBuilder oSBClause = new StringBuilder(" WHERE ");
oSBClause.Append("(VAnnu.AnnuaireId = VAnnu.AnnuaireId) ");

if (intBuId > 0)
{
oSBClause.Append(" AND (VAnnu.BuId = " + intBuId.ToString() + ")
");
}

if (intSSId > 0)
{
oSBClause.Append(" AND (VAnnu.FunctionId = " +
intSSId.ToString() + ") ");
}
if (intREId > 0)
{
oSBClause.Append(" AND (VAnnu.RegionId = " + intREId.ToString()
+ ") ");
}
if (intCOId > 0)
{
oSBClause.Append(" AND (VAnnu.ContractId = " +
intCOId.ToString() + ") ");
}
if (intJobId > 0)
{
oSBClause.Append(" AND (VAnnu.JobId = " + intJobId.ToString() +
") ");
}
if (strSearch != "")
{
oSBClause.Append(" AND LOWER(");
oSBClause.Append(" isnull(VAnnu.AnnuaireLastName + ' ','') +");
oSBClause.Append(" isnull(VAnnu.AnnuaireFirstName + ' ','') +");
oSBClause.Append(" isnull(VAnnu.AnnuaireMail + ' ','') +");
oSBClause.Append(" isnull(VAnnu.JobTitle + ' ','') +");
oSBClause.Append(" isnull(VAnnu.LocationName + ' ','')");
oSBClause.Append(" ) like lower('%");
oSBClause.Append((string)strSearch);
oSBClause.Append("%') ");
}
oSBSQL.Append(oSBClause.ToString());
using (SqlConnection oConn = new SqlConnection("context
connection=true"))
{
SqlCommand oCmd;
oConn.Open();
oCmd = new SqlCommand(oSBSQL.ToString(), oConn);
SqlContext.Pipe.ExecuteAndSend(oCmd);
oConn.Close();
}
}
};
Quelqu'un saurait me dire s'il est possible d'ajouter cette option ? Si oui
avec quelle syntaxe ?

D'avance merci

Laurent Jordi
http://www.ezlogic.mc