Connect to SQL server 2005 using SQLDMO

  • Thread starter João Santa Bárbara
  • Start date
J

João Santa Bárbara

Hi all
i need to know if sql dmo can connect to SQL server 2005
if can! how can i do this ??

i have this code

Dim xServer a SQLDMO.Server
......bla..bla...

xServer.LoginSecure = True
xServer.Connect("SQLServer2005")

but it can´t connect.
is there anyother way ??

thks
JSB
 
K

Ken Tucker [MVP]

Hi,

What are you trying to do with sqldmo?

Ken
-----------------
Hi all
i need to know if sql dmo can connect to SQL server 2005
if can! how can i do this ??

i have this code

Dim xServer a SQLDMO.Server
......bla..bla...

xServer.LoginSecure = True
xServer.Connect("SQLServer2005")

but it can´t connect.
is there anyother way ??

thks
JSB
 
K

Ken Tucker [MVP]

Hi,

Use the sp_databases stored procedure to list database names.

Dim strConn As String

Dim conn As SqlConnection

Dim cmd As SqlCommand

Dim dr As SqlDataReader

strConn = "Server =(local);"

strConn &= "Database = ; Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

cmd = New SqlCommand("sp_Databases", conn)

cmd.CommandType = CommandType.StoredProcedure

conn.Open()

dr = cmd.ExecuteReader

If dr.HasRows Then

Do While dr.Read

Trace.WriteLine(String.Format("Name {0} Size {1}", _

dr.Item("Database_Name"), dr.Item("Database_Size")))

Loop

End If

dr.Close()

conn.Close()





Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top