Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected internal virtual int getUserRefecenceCount(int sqlServerId, string databaseName, string userName)
- {
- ServerDb objServerDb = new ServerDb(dbObj, sqlServerId, ServerDb.ServerType.SQL_SERVER);
- SqlAutomation.SQLDatabase sqlDbObj = new SqlAutomation.SQLDatabase(objServerDb.Serverurl, objServerDb.Username, objServerDb.Password, databaseName);
- SqlCommand command = new SqlCommand();
- 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 + "'";
- log.info(query);
- command.CommandText = query;
- string conString = "Data source=" + objServerDb.Serverurl + ";Initial catalog=master;uid=" + objServerDb.Username + ";password=" + objServerDb.Password + ";";
- log.info(conString);
- SqlConnection sqlCon = new SqlConnection(conString);
- command.Connection = sqlCon;
- sqlCon.Open();
- int refCount = Convert.ToInt32(command.ExecuteScalar());
- sqlCon.Close();
- return refCount;
- }
Add Comment
Please, Sign In to add comment