Create my own db connection wizard

C

Carlo Stonebanks

I would like my app to have its own run-time data connection wizard so that
users can connect to a data source of their choice. I'm new to ADO.NET,
previously programing for RDO/ODBC. With that, I could actually invoke the
Data Source wizard from the Windows System, browse/edit/add a data source
and then pass it back to the program.

The ODBC technique had the advantage of providing a wizard with the ODBC
provider's own interface, complete with proprietary connection properties
and drivers.

How do I replicate this functionality with ADO.NET?

Carlo
 
W

William \(Bill\) Vaughn

The ADO.NET 2.0 factory classes can return the "visible" data providers and
the servers/instances of those database providers.
This is a subset of an example from my new book that enumerates the visible
data sources...
Private Sub ShowServerInstances()

' List Providers

Dim tblProviders As Data.DataTable = DbProviderFactories.GetFactoryClasses

DataGridView2.DataSource = tblProviders

' List Server Instances for a selected provider

Dim factory As DbProviderFactory =
DbProviderFactories.GetFactory("System.Data.SqlClient")

Dim dsE As DbDataSourceEnumerator = factory.CreateDataSourceEnumerator

Dim dtInstances As DataTable = dsE.GetDataSources

DataGridView1.DataSource = AddServiceName(dtInstances)

End Sub

hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
C

Carlo Stonebanks

Thanks Bill,

Of course, the first question is: what's the title of the book, and when
will it be published?

The second question is: only the sqlClient has the value
CanCreateDataSourceEnumerator set to true. What can be done about finding
the available data sources for the other providers (particularily ODBC and
OleDb?

Carlo
 
W

William \(Bill\) Vaughn

"Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)".
In the case of ODBC or OLEDB it's going to be more difficult as these
"providers" don't necessarily expose themselves when polled. For example, an
ODBC or OLEDB interface to JET would not have any mechanism to report the
existence of the database. Oracle can do this as it's a "service"-type
server but its OleDb provider must expose this functionality. That's why the
tools in VS make you point to most of these data sources manually to
"register" them.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
J

james

William (Bill) Vaughn said:
The ADO.NET 2.0 factory classes can return the "visible" data providers
and the servers/instances of those database providers.
This is a subset of an example from my new book that enumerates the
visible data sources...
Private Sub ShowServerInstances()

' List Providers

Dim tblProviders As Data.DataTable = DbProviderFactories.GetFactoryClasses

DataGridView2.DataSource = tblProviders

' List Server Instances for a selected provider

Dim factory As DbProviderFactory =
DbProviderFactories.GetFactory("System.Data.SqlClient")

Dim dsE As DbDataSourceEnumerator = factory.CreateDataSourceEnumerator

Dim dtInstances As DataTable = dsE.GetDataSources

DataGridView1.DataSource = AddServiceName(dtInstances)

End Sub

hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________


Hi Bill, sounds like I'll be adding another book to my collection! I can get
your example to work using :
Imports System.Data.Common
But, this line is giving me fits:

DataGridView1.DataSource = AddServiceName(dtInstances)

I get an error that "AddServiceName" is not defined. Looking in the Factory
Class I cannot find a reference to that anywhere.
I know this was a partial example, but, I like trying things to see the
results and besides, there are times I end up needing the info . I can
comment that line out and the rest works great. But, I am stumped to get
the other part working.
Any free clues ? Or do I need to wait till I get the book ? :)

Sorry to (slightly) hijack this thread, I just found the topic interesting
and the example interesting as well.
james
 
W

William \(Bill\) Vaughn

Ah, that's in another part of the example... sorry for the oversight.
Private Function AddServiceName(ByVal dtLi As DataTable) As DataTable

Dim colService As New DataColumn("ServiceName", GetType(String))

dtLi.Columns.Add(colService)

Dim colState As New DataColumn("Status", GetType(String))

dtLi.Columns.Add(colState)

For Each dr As DataRow In dtLi.Rows

dr("ServiceName") = DBNull.Value

If Not IsDBNull(dr("Version")) Then

dr("ServiceName") = "MSSQL$" & dr("InstanceName")

Else

dr("ServiceName") = "MSSQLSERVER"

End If

dr("Status") = GetStatusForService(dr("ServiceName"), dr("ServerName"))

Next

Return dtLi

End Function





--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
C

Carlo Stonebanks

Which in turn begs the question, what does
GetStatusForService() do?

The fun never stops. Aren't you glad you gave your code away?

;-D

Carlo
 
W

William \(Bill\) Vaughn

Oh well. It polls the service status from the ServiceProcess.

Private Function GetStatusForService(ByVal strServiceName As String, ByVal
strServerName As String) As String

Try

Dim Controller As New
System.ServiceProcess.ServiceController(strServiceName, strServerName)

Return Controller.Status.ToString

Catch ex As Exception

Return ex.Message

End Try

End Function


I guess you'll have to come to my VSLive workshop where I'll be showing the
entire code sample. I'll be happy to give you access to the code if you see
me at TechEd Boston. I'll be hanging around the TLC when I'm not eating
lobster somewhere...

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
J

james

Thanks Bill, finally figured out for the "GetStatusForService" function,
that I needed to add a Reference to System.ServiceProccess. Once I did that,
it all works great. (amazing what happens when your forced to think!!)
Thanks again.
james
 
J

james

William (Bill) Vaughn said:
I guess you'll have to come to my VSLive workshop where I'll be showing
the entire code sample. I'll be happy to give you access to the code if
you see me at TechEd Boston. I'll be hanging around the TLC when I'm not
eating lobster somewhere...

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________


Wish I could be there Bill. How about this, since you are an INETA speaker,
maybe, you could give a presentation to the Fort Worth DotNet User's Group.
And give a presentation on this subject!! I know that lots of people in our
group would be interested in the subject. If that's a possibility, I can
get you contact information with our group.
james
 
W

William \(Bill\) Vaughn

As a matter of fact, I'm going to be in Abilene the week of June 26th to
help my daughter move to Dyess. I would be more than happy to come talk to
your UG that week sometime. Have your people talk to the INETA people ASAP
as they are trying to hook me up with north Texas user groups.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
J

james

Bill, I have forwarded this post , along with a message from me to our
group's president, Stephen Swenton. Hopefully, he can get in touch with you
and INETA and make arrangements for you to speak. Usually, our group meets
the 3rd Tuesday of each month at the Justin Brands Company's office area in
Ft.Worth. There have been a couple of times where the meeting was changed to
accomodate a speaker's schedule or because the meeting room we use was
scheduled for another event.
Hopefully, Stephen can get with you and INETA and work something out.
james
 
W

William \(Bill\) Vaughn

If that's the case make sure you pick the topic... ;)

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

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