AndyLee100
Technical User
Hi,
I have a real problem trying to add a user in VB.Net using SQLDMO. The real crux is that the code works in VB 6.
Would appreciate any help as this problem is doing my head in. Code below-
Any help would be greatly appreciated.
Thanks
Andy Lee
I have a real problem trying to add a user in VB.Net using SQLDMO. The real crux is that the code works in VB 6.
Would appreciate any help as this problem is doing my head in. Code below-
Code:
Dim oServerName As New SQLDMO.SQLServer
Dim oDBLogin As New SQLDMO.Login
Dim oDBUser As New SQLDMO.User
Dim odbname As New SQLDMO.Database
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sDatabaseName As String
oServerName.Connect("pc-andy", "sa", "password")
sDatabaseName = "Pubs"
With oDBLogin
.Database = "pubs"
.Name = "is"
.SetPassword("", "Password")
.Type = SQLDMO.SQLDMO_LOGIN_TYPE.SQLDMOLogin_Standard
End With
oServerName.Logins.Add(oDBLogin)
'odbname = oServerName.Databases(sDatabaseName)
With oDBUser
.Name = "XXX"
.Login = oDBLogin.Name
End With
odbname = oServerName.Databases(sDatabaseName)
(This is the line it doesnt like!!!)
Error - 'Interface 'SQLDMO.Databases' cannot be indexed because it has no default property.'
odbname.Users.Add(oDBUser)
End Sub
Any help would be greatly appreciated.
Thanks
Andy Lee