Guest User

Untitled

a guest
Jun 13th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. protected internal virtual int getUserRefecenceCount(int sqlServerId, string databaseName, string userName)
  2. {
  3. ServerDb objServerDb = new ServerDb(dbObj, sqlServerId, ServerDb.ServerType.SQL_SERVER);
  4. SqlAutomation.SQLDatabase sqlDbObj = new SqlAutomation.SQLDatabase(objServerDb.Serverurl, objServerDb.Username, objServerDb.Password, databaseName);
  5.  
  6. SqlCommand command = new SqlCommand();
  7. string query = "Use \"" + databaseName + "\" SELECT COUNT(o.Name) FROM sys.schemas s INNER JOIN sys.database_principals d ON s.principal_id = d.principal_id JOIN sys.objects o ON (s.schema_id = o.schema_id) WHERE d.name = '" + userName + "'";
  8. log.info(query);
  9. command.CommandText = query;
  10. string conString = "Data source=" + objServerDb.Serverurl + ";Initial catalog=master;uid=" + objServerDb.Username + ";password=" + objServerDb.Password + ";";
  11. log.info(conString);
  12. SqlConnection sqlCon = new SqlConnection(conString);
  13. command.Connection = sqlCon;
  14. sqlCon.Open();
  15. int refCount = Convert.ToInt32(command.ExecuteScalar());
  16. sqlCon.Close();
  17.  
  18. return refCount;
  19. }
Add Comment
Please, Sign In to add comment