connection to sql server

  • I am trying to connect to sql server through my application by using VB.NEt. I try SQLServer.Connect("myserver", "sa", ""), but I am getting an error. The error is something about an "unhandled win32 exception". Can any one help with this. I am a newbie to sql dmo and What are the steps to connect to sql server 2000 ?

    Any help is appreciated.

  • Oh man, I see I going to pay for not spending much time on .Net so far! Your syntax looks right as far as DMO...server, username, password. I'll try to find time to experiment at work today. Maybe someone else has tried this??


  • I don't think its a problem with my VB.NET code, but I'm not sure. I get an error, but it says that it cannot catch the other and says something about "unhandled win32 exception". To access the DMO objects, all I have to do is include the object library right ? Or is there more that I need to do?

    Here is my code if it helps. This function is supposed to create a new sql server login account after the user enters a username and password and clicks a button. Thanks for any help:

    Private Sub createButton_Click(ByValsender As System.Object, ByVal e As System.EventArgs) Handles createButton.Click

    Dim objServer As SQLDMO.SQLServer

    Dim objLogin As SQLDMO.Login

    On Error Goto ErrorHandler

    'connect to server

    objServer = New SQLDMO.SQLServer()

    objServer.Connect("(local)", "Test", "password")

    'create new login

    objLogin = New SQLDMO.Login()

    objLogin.Name = userNameBox.Text

    objLogin.SetPassword("", passwdBox.Text)

    objLogin.Database = "RealTrakH"

    'add to logins collection




    MessageBox.Show(Err.Number & Err.Description & Err.Source)

    End Sub

  • One thing I see is no 'exit sub' right before your error handler label. Also, shouldnt you be using a try/catch block instead of on error resume next?


  • Well after days of searching I finally found the answer. In declaring the SQLServer variable and initializing it you must add underscores, it must be:

    Dim objServer As SQLDMO._SQLServer

    objServer = New SQLDMO.__SQLServer()

    Weird, I know, but it works.

  • Anyone know why? Pretty common for a _ to be used to hide a method that you dont normally want called (right click in VB6 object browser to see the unhide setting) but that doesnt seem to be the case here.


Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply