Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - SQL connection string encoded in a Uri?

Reply
 
Old 11-26-2008   #1 (permalink)
Lou


 
 

SQL connection string encoded in a Uri?

I've been looking for an established way to encode a connection string into a
Uri. Uri's are used for file access using File://path. Has anyone seen a
Sql://server/db/table?query approach?

Thanks

My System SpecsSystem Spec
Old 11-26-2008   #2 (permalink)
Jeroen Mostert


 
 

Re: SQL connection string encoded in a Uri?

Lou wrote:
Quote:

> I've been looking for an established way to encode a connection string into a
> Uri. Uri's are used for file access using File://path. Has anyone seen a
> Sql://server/db/table?query approach?
>
Sure, JDBC uses this method -- not URIs, precisely, but syntax that
resembles them. For example, a connection string for SQL Server using the
jTDS driver looks like this:

jdbc:jtds:sqlserver://<server>\<instance>:<port>/<database>

The question is, why would you want to do this for .NET connection strings?
Those have an established format too, it just doesn't resemble a URI. The
general format is just simple key=value pairs, separated by semicolons:

Provider=<provider>;<param>=<value>;...

There's any number of ways you can stuff this in a URI, but you'll have to
roll your own mechanism for encoding and decoding them (the Uri class is
only of limited help here). But again, why would you? Is there some place
you can store URIs but not general strings?

Note that it's a very bad idea to allow arbitrary queries and pass those
around as URIs, for reasons I hopefully don't have to elaborate. You may
want to look at a REST approach to resources instead, but without tying
those to specific database tables. Take a look at ADO.NET Data Services, for
example: http://msdn.microsoft.com/data/bb931106

--
J.
My System SpecsSystem Spec
Old 11-26-2008   #3 (permalink)
Lou


 
 

Re: SQL connection string encoded in a Uri?

Jeroen,

Thanks, so I'm not crazy. What I'm after here is a way to store a location
for a data source or sink. I want to keep a uniform link for ANY source or
sink. Why should there be a way to connect to a web site/FTP/Mail/File etc
and not have a way to use that same Uri (emphasis on Universal) without
someway of including SQL in the mix?

I'm prepared to 'roll my own' on this. It's an internal thing. I suppose
since most SQL server access is managed intermurrally having a URI wouldn't
provide universal access but I'm looking for consistency of declaration.
Otherwise I'd have to check to see if the string was a connection string or a
URI. Not so terrible I guess but not quite esthetic. :-)

Lou

"Jeroen Mostert" wrote:
Quote:

> Lou wrote:
Quote:

> > I've been looking for an established way to encode a connection string into a
> > Uri. Uri's are used for file access using File://path. Has anyone seen a
> > Sql://server/db/table?query approach?
> >
> Sure, JDBC uses this method -- not URIs, precisely, but syntax that
> resembles them. For example, a connection string for SQL Server using the
> jTDS driver looks like this:
>
> jdbc:jtds:sqlserver://<server>\<instance>:<port>/<database>
>
> The question is, why would you want to do this for .NET connection strings?
> Those have an established format too, it just doesn't resemble a URI. The
> general format is just simple key=value pairs, separated by semicolons:
>
> Provider=<provider>;<param>=<value>;...
>
> There's any number of ways you can stuff this in a URI, but you'll have to
> roll your own mechanism for encoding and decoding them (the Uri class is
> only of limited help here). But again, why would you? Is there some place
> you can store URIs but not general strings?
>
> Note that it's a very bad idea to allow arbitrary queries and pass those
> around as URIs, for reasons I hopefully don't have to elaborate. You may
> want to look at a REST approach to resources instead, but without tying
> those to specific database tables. Take a look at ADO.NET Data Services, for
> example: http://msdn.microsoft.com/data/bb931106
>
> --
> J.
>
My System SpecsSystem Spec
Old 11-28-2008   #4 (permalink)
Jeroen Mostert


 
 

Re: SQL connection string encoded in a Uri?

Lou wrote:
Quote:

> Actually, you've answered my original question which is whether it's
> possible (acceptable) to distort a URI to encode a SQL source/Sink location.
> I'm not actually thinking of using it as a 'message' per se. I just want to
> be able to handle requests for data sources and sinks uniformly. To give you
> a bit of a scenario: in my company, and probably in many, there are
> occasionally requests that go out to field people to provide data in some
> form. Sometimes it's Excel, sometimes it's in a formatted form etc. This
> data is then returned by email and compiled into another spreadsheet (yes, a
> fairly primitive thought process.) After a couple of these experiences I
> decided to build something that would take a source document like a
> spreadsheet, take the column names and types, store them and use it to
> recreate a sink in whatever destination is identified by some description.
> Uri's seemed to be appropriate but there are some holes, most notably SQL
> resources. So, thanks for that.
>
The big impedance mismatch I see is that URIs (Uniform Resource Identifiers)
are meant to uniquely label things, often more specifically by use of a
location (the ever popular URLs). What they're not good at is additionally
embedding the format of the thing you're labeling, and they're almost never
used for that.

For example, http://www.microsoft.com describes a resource accessed through
the HTTP protocol, but it doesn't tell you anything about HTML -- that's
outside the scope. Similarly, an sql:// URI could specify a table in a
database on a server, but it's not natural to use it to describe the table's
structure as well.

So you could use URIs for the sources and destinations of the messages as
you describe them, but you would need to lay down the format of those
messages quite rigidly, or a way to figure out the format for each URI
scheme. If you've only ever got one format that's not so hard, but otherwise
you need some good error handling strategies ("whoops, the table's structure
doesn't match my spreadsheet, I'll guess I'll just cut a few columns").
Quote:

> I can see, however, from the issues you've pointed out that there's probably
> a good reason why SQL:// is not 'out there' much as a URI to retrieve SQL
> data. It's ironic since SQL data stores are probably where most of the
> world's data resides. I'm sure query formatting probably could be devised to
> get data, even in arbitrarily complex ways. I wonder why that formatting
> hasn't been addressed as since just about everything else has been serialized
> in some way and passed through some standard parser to get to the various
> flavors of SQL Queries.
>
What you're really clamoring for (a uniform way to access databases) has
already been described: it's ANSI SQL. Squeezing all of it into URI form
would be a hell of a job (and you'd end up with some ridiculously big and
unreadable URIs). You could turn the URI into a simple "inject any
system-specific query here" endpoint, but if you do that there's really no
benefit over just exposing a script or application over HTTP to do the same.

Recapping: I could see URIs being used to point to a table or view on an
arbitrary server, but anything more complicated than that goes against the
nature of URIs.

--
J.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
SQL Server connection string for deployment ? .NET General
Web.config and Connection String Management .NET General
Help with connection string .NET General
Re: Inserting LDAP server into connection string?? VB Script
ASP connection string to SQL2005 VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46