开发者

Failure to create a SQL Azure login with SMO

开发者 https://www.devze.com 2023-02-10 17:51 出处:网络
The following piece of code works with regular SQL and SMO. I\'m trying to get it to work with SQL Azure. According to this MSDN article, a limited subset of functionality that I need (database and lo

The following piece of code works with regular SQL and SMO. I'm trying to get it to work with SQL Azure. According to this MSDN article, a limited subset of functionality that I need (database and login creation) should be supported. All the business checking whether an object exists will also fail: server.Logins[loginName] != null or server.Databases.Contains(dbName). I can create a database if I dont check whether it exists or not, but i cant create a login. Anyone else ran into the same problem?


string connectionString = 
"Server=tcp:XXXXXX.database.windows.net;Database=MyDatabase;User ID=XXXXXXX;Password=XXXXXX;Trusted_Connection=False;Encrypt=True;TrustServerCertificate=true;"

using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();
    ServerConnection serverConnection = new ServerConnection(connection);
    Server server = new Server(serverConnection);

    Login login 开发者_JS百科= new Login(server, "NewLogin");
    login.LoginType = LoginType.SqlLogin;
    login.Create("NewStrongPwd123***");
}

Create failed for Login 'NewLogin'.

at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()

at Microsoft.SqlServer.Management.Smo.Login.Create(SecureString password)

at Microsoft.SqlServer.Management.Smo.Login.Create(String password)


Proposed answers to this question were identified on the MSDN Forum including a working approach. Please take a look at: http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/26e42082-e649-4cde-916d-c1da2275e377

0

精彩评论

暂无评论...
验证码 换一张
取 消