ADO.NET connection string creation using Dialogs.

  • Thread starter Thread starter Daniel Bello Urizarri
  • Start date Start date
D

Daniel Bello Urizarri

Hello:

Is there any way in the new ado.net 2.0 to create a connection string using
a dialog from the application?

It was possible using the classic ado objects.
Is there some similar thing here?

Thanks.
 
Daniel,
AFAIK, the same way as in .net 1.1.

Add a reference to Microsoft OLE DB Service Component 1.0 Type Library and try

object connection = new ADODB.Connection();
((ADODB.Connection)connection).ConnectionString = connectionString;
MSDASC.DataLinks dataLinks = new MSDASC.DataLinks();

if (dataLinks.PromptEdit(ref connection))
{
connectionString = ((ADODB.Connection)tempConnection).ConnectionString;
}

All the Best,
Phil.
 
Hello:

Yes, of course, using ADO is still possible, but I'm thinking in the future.
My application can be running in a non windows plattform.

I already have made some dialogs, using reflection on the version 1.1 of the
framework, and I'm glad to see that the new DbProviderFactories, even the
class DbConnectionStringBuilder is now available.

Unfourtunatly, it seems that the dialogs are not.

Thanks for your help.
 
Yes Sahil:

I have red the answers.. but is not what im looking for.. I already know
that those methods exists, in fact in my application, if MDAC is installed,
I show the dialog for OleDb connections, and my own dialogs, for SqlServer,
MySql (using bytefx ,net native driver) or oracle.

But I was asking if any one knew if the dialogs are supported by the
framework. For example, Visual Studio 2005 uses its own wizard, and is not
using the mdac componets or opening some udl file.. Unfortunatley those
dialogs are not in the framework, and they seems to be part of the Visual
Studio.

People will need to continue building their own dialogs, or making cross
platform tricks like opening an udl file or calling via interop the old Ado
components.

Thanks.
 
Daniel,
People will need to continue building their own dialogs, or making cross
platform tricks like opening an udl file or calling via interop the old
Ado
components.
Are you sure you are talking in the old situation about OleDB, the ODBC
situation is not changed and people can make than their own dialogs.

I hope this helps,

Cor
 
Hi Cor:

I'm talking about having to do this:


private string CreateOledbConnectionString ()
{
try
{
Interop.Db.IDataSourceLocator mydlg = (Interop.Db.IDataSourceLocator)new
Interop.Db.DataLinksClass ();
mydlg.hWnd = (int)this.Handle;
Interop.Db._Connection ADOcon = (Interop.Db._Connection)new
Interop.Db.ConnectionClass();

Hashtable ht = LtnDDBB.ParseConnectionString ( tCString.Text );
ADOcon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist
Security Info=False";

object ADOconAux = ADOcon;

return = _ConnectionString =
( mydlg.PromptEdit( ref ADOconAux ) ) ?
ADOcon.ConnectionString : ""; //All OK
}
catch
{
//Error. Probably MSDASC is not available
}

//If MSDASC is not available, show my own dialog
return CreateConnection ( new Db.OledbCSBuilder () );
}



Using this: (The rason to not use simple iterop (using references) is that
I'm developing a class library (.dll) and using interop makes me carry with
more .dlls as Interop.ADOX.dll).




namespace Interop.Db
{
[Guid("2206CDB2-19C1-11D1-89E0-00C04FD7A829")]
[ComImport]
[TypeLibType((short)2)]
[ClassInterface(ClassInterfaceType.None)]
internal class DataLinksClass // : IDBPromptInitialize, IDataInitialize,
IDataSourceLocator, DataLinks
{
}
[Guid("00000514-0000-0010-8000-00AA006D2EA4")]
[ComImport]
[TypeLibType((short)6)]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces("ConnectionEvents")]
internal class ConnectionClass // : _Connection, Connection,
ConnectionEvents_Event
{
}
[Guid("2206CCB2-19C1-11D1-89E0-00C04FD7A829")]
[ComImport]
[TypeLibType((short)4160)]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
internal interface IDataSourceLocator
{
[DispId(1610743810)]
[return: MarshalAs(UnmanagedType.IDispatch)]
object PromptNew ();

[DispId(1610743811)]
[return: MarshalAs(UnmanagedType.VariantBool)]
bool PromptEdit ([In, Out, MarshalAs(UnmanagedType.IDispatch)] ref object
ppADOConnection);

int hWnd
{
[DispId(1610743808)]
get;
[DispId(1610743808)]
set;
}
}


[Guid("00000550-0000-0010-8000-00AA006D2EA4")]
[ComImport]
[TypeLibType((short)4160)]
[DefaultMember("ConnectionString")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
internal interface _Connection
{
[DispId(5)]
void Close ();

object Execute ([MarshalAs(UnmanagedType.BStr)] string CommandText, [Out]
out object RecordsAffected, int Options);

[DispId(7)]
int BeginTrans ();

[DispId(8)]
void CommitTrans ();

[DispId(9)]
void RollbackTrans ();

[DispId(10)]
void Open ([MarshalAs(UnmanagedType.BStr)] string ConnectionString,
[MarshalAs(UnmanagedType.BStr)] string UserID,
[MarshalAs(UnmanagedType.BStr)] string Password, int Options);

[DispId(19)]
object OpenSchema (object Schema, object Restrictions, object SchemaID);

[DispId(21)]
void Cancel ();

int Attributes
{
[DispId(14)]
get;
[DispId(14)]
set;
}

int CommandTimeout
{
[DispId(2)]
get;
[DispId(2)]
set;
}

string ConnectionString
{
[DispId(0)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
[DispId(0)]
set;
}

int ConnectionTimeout
{
[DispId(3)]
get;
[DispId(3)]
set;
}

object CursorLocation
{
[DispId(15)]
get;
[DispId(15)]
set;
}

string DefaultDatabase
{
[DispId(12)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
[DispId(12)]
set;
}

object Errors
{
[DispId(11)]
get;
}

object IsolationLevel
{
[DispId(13)]
get;
[DispId(13)]
set;
}

object Mode
{
[DispId(16)]
get;
[DispId(16)]
set;
}

object Properties
{
[DispId(500)]
get;
}
string Provider
{
[DispId(17)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
[DispId(17)]
set;
}

int State
{
[DispId(18)]
get;
}

string Version
{
[DispId(4)]
[return: MarshalAs(UnmanagedType.BStr)]
get;
}
}
}
 
Hmm .. but I have to ask, what is wrong with the previous methods? (And
there might be a new way of doing this, maybe I just don't know about it).

_ SM
 
Daniel,

This is complex and difficult work.

If you know that in RC1 from 2005 the server explorer does not show the
servers anymore, than I hope that you understand that you are on a very time
consuming route at the moment.

You can find the SQLserver using SQLDMO if you are interested in that.
However, that is an object from SQL itself.

Cor
 
Hi Cor:

I use to use Udp protocol to ask for SqlServers and it works very well for
me, but on the new framework there is a way:

DbDataSourceEnumerator.GetDataSources()

So, you can forget about SQLDmo, and work only with the ADO.Net 2.0 objects

Daniel
 
Hi Sahil:

What is wrong for me is that probably in Linux using Mono, opening a .udl
file does not result in a dialog open on the system.
Maybe the mdac runs on Wine and I can reference its objects, Im not sure it
is not possible. I'm not a Linux user. Buy i have to guarantee that the
class library im doing runs on all systems. (Even on pocket pcs, although
I'm not asking for dialogs there.)
I was thinking that re-designing the ado.net will be a nice moment to add
things like that.
On the other hand all it is only valid for oledb and odbc providers, What
about the new Ado.net data providers? There should be a uniform way for them
to.

Thanks for your interest.
Daniel Bello
 
Daniel,

..NET 2.0 does have a DB provider factory, not sure if it's made it's way to
Mono yet. Sorry but I've never really worked with Mono :(

- SM
 
Hi:

As it is part of the model, I'm sure that mono will incorporate it at some
moment.

Daniel
 
Back
Top