PC Review


Reply
Thread Tools Rate Thread

DataConnection wizard in application

 
 
=?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=
Guest
Posts: n/a
 
      30th Jan 2007
I need to let the users change data connection in runtime.
I tried to let them specify the SQL connection string by hand, but it is
quite complicated to remember and an error is fatal.

I read somewhere that it should be possible to use the inbuilt connection
wizard used by the Visual Studio IDE. That would certainly be much more
elegant!
Is it possible? How can it be done?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFyayBOZWxzb24=?=
Guest
Posts: n/a
 
      30th Jan 2007
Jakob Lithner,

I played with the Connection String wizard of VS 2005 IDE. During
configuration you can switch between connection strings. When you are trying
to specify a connection string IDE asks you whether to save in the app.config
file. If you say yes, all the connection strings are stored in the
app.config file like the following.

<configuration>
<configSections>
</configSections>
<connectionStrings>
<add
name="DynamicConnection.Properties.Settings.AdventureWorksConnectionString"
connectionString="Data Source=CTSINTCOSGTO1;Initial
Catalog=AdventureWorks;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add
name="DynamicConnection.Properties.Settings.masterConnectionString"
connectionString="Data Source=ctsintcosgto1;Initial
Catalog=master;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

But this does not provide the flexibility of making the user to change to
connection string at runtime. To achieve that, use this app.config and have
the user to select
from UI and thenk figure out accordingly to which database yoiu need to
connect.

The prinicple is that you need to have some identifier or a flag to
decide which connection string to hook-up. This only will achive the
switching of connection strings during run-time

--
Thanks & Regards,
Mark Nelson


"Jakob Lithner" wrote:

> I need to let the users change data connection in runtime.
> I tried to let them specify the SQL connection string by hand, but it is
> quite complicated to remember and an error is fatal.
>
> I read somewhere that it should be possible to use the inbuilt connection
> wizard used by the Visual Studio IDE. That would certainly be much more
> elegant!
> Is it possible? How can it be done?

 
Reply With Quote
 
=?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=
Guest
Posts: n/a
 
      30th Jan 2007
Thanks for your suggestion.
But as you say yourself this will only take you part of the way.
I still hope for a fully flexible solution where the user can configure and
test a specified connection.
 
Reply With Quote
 
Otis Mukinfus
Guest
Posts: n/a
 
      30th Jan 2007
On Tue, 30 Jan 2007 04:02:00 -0800, Jakob Lithner <(E-Mail Removed)>
wrote:

>I need to let the users change data connection in runtime.
>I tried to let them specify the SQL connection string by hand, but it is
>quite complicated to remember and an error is fatal.
>
>I read somewhere that it should be possible to use the inbuilt connection
>wizard used by the Visual Studio IDE. That would certainly be much more
>elegant!
>Is it possible? How can it be done?


This should get you started. It's not the wizard, but it works.

Add a PropertyGrid object to a form and let them fill in the property grid.

Here is some code from a form that does that:

private void testForm_Load(object sender, EventArgs e)
{
SqlConnectionStringBuilder _sqlBldr = new SqlConnectionStringBuilder();
//propGrid.SelectedObject = _sqlBldr;
sqlServerRadioButton.Checked = true;
_cnType = "SQL";
}

private void copyButton_Click(object sender, EventArgs e)
{
switch (_cnType)
{
case "SQL":
if (_sqlBldr.ConnectionString != "")
Clipboard.SetDataObject(_sqlBldr.ConnectionString);
break;
case "OLE":
if (_oleBldr.ConnectionString != "")
Clipboard.SetDataObject(_oleBldr.ConnectionString);
break;
case "ORA":
if (_oraBldr.ConnectionString != "")
Clipboard.SetDataObject(_oraBldr.ConnectionString);
break;
}
}
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
Reply With Quote
 
Linda Liu [MSFT]
Guest
Posts: n/a
 
      31st Jan 2007
Hi Jakob,

I am sorry I don't think there's a way for us to use the inbuilt connection
wizard used by the Visual Studio IDE in our own program.

But .NET 2.0 has brought us SqlConnectionStringBuilder class, which
provides a simple way to create and manage the contents of connection
strings used by the SqlConnection class.

I suggest that you create a UI for the user to specify each part of the
connection string and then use SqlConnectionStringBuilder to construct a
complete connection string.

For more information on SqlConnectionStringBuilder class and how to use it,
you may visit the following link.

'SqlConnectionStringBuilder Class'
http://msdn2.microsoft.com/en-us/lib....sqlconnection
stringbuilder.aspx

Hope this helps.
If you have anything unclear, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Larry Dodd
Guest
Posts: n/a
 
      31st Jan 2007
Here is an example of how to use the Property Grid to work with SQL
Connection strings. You will find the example in the download.

http://www.codeproject.com/vb/net/us...opertygrid.asp



"Jakob Lithner" <(E-Mail Removed)> wrote in message
newsECD1DA0-9045-432B-9168-(E-Mail Removed)...
> Thanks for your suggestion.
> But as you say yourself this will only take you part of the way.
> I still hope for a fully flexible solution where the user can configure
> and
> test a specified connection.


 
Reply With Quote
 
=?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=
Guest
Posts: n/a
 
      31st Jan 2007
The SqlConnectionStringBuilder is a good help.
I can easily provide my own GUI to manipulate the different settings.

BUT: How do I save the resulting ConnectionString to my ConnectionString
setting?
I suddenly found out that this setting is ReadOnly!
Why is that? Is it not possible to override or change through some other
method?
 
Reply With Quote
 
LLcoolQ@gmail.com
Guest
Posts: n/a
 
      31st Jan 2007
On Jan 30, 10:27 pm, v-l...@online.microsoft.com (Linda Liu [MSFT])
wrote:
> Hi Jakob,
>
> I am sorry I don't think there's a way for us to use the inbuilt connection
> wizard used by the Visual Studio IDE in our own program.
>
> But .NET 2.0 has brought us SqlConnectionStringBuilder class, which
> provides a simple way to create and manage the contents of connection
> strings used by theSqlConnectionclass.
>
> I suggest that you create a UI for the user to specify each part of the
> connection string and then use SqlConnectionStringBuilder to construct a
> complete connection string.
>
> For more information on SqlConnectionStringBuilder class and how to use it,
> you may visit the following link.
>
> 'SqlConnectionStringBuilder Class'http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcon...
> stringbuilder.aspx
>
> Hope this helps.
> If you have anything unclear, please feel free to let me know.
>
> Sincerely,
> Linda Liu
> Microsoft Online Community Support
>
> ==================================================
> Get notification to my posts through email? Please refer tohttp://msdn.microsoft.com/subscriptions/managednewsgroups/default.asp...
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) athttp://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.


Here is a good example of what I think you are looking for:

http://adoguy.com/viewrant.aspx?id=2193

jay

 
Reply With Quote
 
=?Utf-8?B?SmFrb2IgTGl0aG5lcg==?=
Guest
Posts: n/a
 
      31st Jan 2007
Interesting suggestion according to my initial track!
But for a couple of reasons I am still a bit hesitant:

1) Is it possible to enter current connection and let the user adjust it or
is it necessary to always define a new connection from scratch?

2) How about the licensing? These files are placed in a directory intending
that they are not part of the runtime environment. Are you sure you can
include these files in the deployment?
 
Reply With Quote
 
Linda Liu [MSFT]
Guest
Posts: n/a
 
      1st Feb 2007
Hi Jakob,

Yes, you're right that the ConnectionString setting is readonly. The
desginers of application settings consider the connection string setting
should not be modified at run time. So this behavior is by design.

If you do want to change the connection string and save it to the
configuration file at run time, you may do it using ConfigurationManager
and Config classes to accomplish this task.

The following is a sample. Note that you should add a reference to
System.Configuration.dll into the project first.

Imports System.Configuration

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim config As Configuration =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

Dim csSection As ConnectionStringsSection =
CType(config.GetSection("connectionStrings"), ConnectionStringsSection)

' the "DataAdapterMapping.My.MySettings.dataconn" is the name of
the connection string setting

csSection.ConnectionStrings("DataAdapterMapping.My.MySettings.dataconn").Con
nectionString = "the new connection string"

config.Save(ConfigurationSaveMode.Modified)

End Sub

Please try my suggestion and let me know the result.


Sincerely,
Linda Liu
Microsoft Online Community Support

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
slow opening for dataconnection Rick Microsoft VB .NET 0 13th Oct 2006 01:25 PM
DataConnection Question? Debbie Carter Microsoft VB .NET 8 9th Oct 2004 06:58 PM
Dataconnection error messages R Microsoft VB .NET 3 5th Feb 2004 02:03 PM
Dataconnection Closes automatically Srinivas Microsoft Dot NET Framework 0 13th Nov 2003 11:34 AM
Global dataconnection John Microsoft ADO .NET 20 6th Nov 2003 12:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:11 PM.