declare @Login nvarchar(255)
declare @Password nvarchar(255)
declare @i int
DECLARE curs CURSOR FOR
SELECT [Login], [Password]
FROM [UsersToCreate]
OPEN curs
FETCH NEXT FROM curs INTO @Login, @Password
set @i=1
WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
exec('CREATE LOGIN ['+@Login+'] WITH PASSWORD = '''+@Password+'''')
exec('CREATE USER ['+@Login+'] FOR LOGIN ['+@Login+'] WITH DEFAULT_SCHEMA = my_sc')
exec('EXEC sp_addrolemember ''my_role'', ['+@Login+']')
END TRY
BEGIN CATCH
print cast(@i as char(3))+ ') login: ' + @Login + ' - error:' + ERROR_MESSAGE()
set @i= @i+1
END CATCH;
FETCH NEXT FROM curs INTO @Login, @Password
END
CLOSE curs
DEALLOCATE curs
четвер, 13 січня 2011 р.
Пример курсора
вівторок, 11 січня 2011 р.
C#, Get Current Path
public static class PathHelper
{
public static string GetCurrentPath()
{
string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
return System.IO.Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path));
}
public static string CombineWithCurrent(string path)
{
return System.IO.Path.Combine(GetCurrentPath(), path);
}
}
Підписатися на:
Дописи (Atom)