Databases...couldn't they be happier?

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Connection String, Connection Strings. They all seem to work through the VB IDE but every time I try to have a little versatility in my app, it doesn't work. and most likely it is because of Connection Strings, or understanding them.

I've been to all the sites, I've read all the documentation, but as with all things the documentation is incomplete because it doesn't expect someone weird to come along and say: oh, so i can do this with that and get this effect....no, i can't.

SQL Express Database, Has SQL Auth, and Windows Auth enabled on it.
And I want both for different roles and purposes.
Computer Name: CORDEFW042
SQL Express Name: SQLEXPRESS
Database name: rexamship

the default string created by the Interface (slightly modifed)
VB.NET:
Data Source=.\SQLEXPRESS;AttachDbFilename=C:\db\rexamship.mdf;Initial Catalog=rexamship;Connect Timeout=30
So it attaches a file (pointless) and give the catalog/database name. fine, I reworked that one to say this:
VB.NET:
Data Source=CORDEFW042\SQLEXPRESS;Initial Catalog=rexamship;Connect Timeout=30

Much better and more appropriate, for really, the attaching of a file is "useful" but in no way should be mandatory the way the IDE tries to make it. I'm connecting to a DB server not transporting some db file with my app.

So, My app retrieves a User/Pass and then updates the string via a ConnectionStringBuilder, adding the User ID=""; and Password=""; fields to the string and all is hunky dory. Now I have a "default" setting in my login selection which allows the user to select "login as windows user", a-hah, the Windows Authentication mode.

So I have the ConnectionStringBuilder set up the string with Integrated Security=True; and User Instance=True; right? isn't that they way the database connection work through the VB IDE, i select windows authentication and those two properties become true, and the UserID/Password properties disappear.

So I try to connect:
Database rexamship not found
Huh, of course it's found it's been found every time i logged in under user/pass. (and yes I have been in the SQL Management Studio and both my user/pass accounts are create along with a permission thing is set up for my windows account, which is flagged as a Window Authorization account in the sql server)
So whether in the VB IDE or through the management studio I can connect as my User Account or My Window Account and both work, i just can't get Windows Auth connection string to work from within my program.

So I thought, well, wait a sec, the User Instance has something to do with the sql server being on the same domain server as the account information (unless it is a local server) so I tried updating the string to say:
.\SQLEXPRESS
instead of the computername\sqlname, because well my computer is not the domain server of all the user accounts, and the VB IDE uses the .\ method instead of the computername\sqlname method; that didn't work either.

I want both, user access and windows access simultaneously, because the windows access is users, so i (and they) don't have to deal with password set up and user creation. But I do want the Sql Authorized user accounts for the administration stuff.

I know I am missing something in the middle here, and it has always been the most poorly documented and designed concept in programming the way connection strings are set up so you never know exactly what will work and if it will work every time. :mad:
On top of that, the test server I'm using now is SqlExpress on my laptop, but when this goes Live it will be on the corporate server, and it might be the full sql 2005, not express, so i'm looking forward to that even though I may get it to work now, i'll be back in some time when it fails in the future. And I can't (no matter what) have that darned AttachDBFilename in there, because in the future I just won't know where that filename is. It will be attached permanently to the server DB as it is to my test one now.
Any suggestions? i've been to
ConnectionStrings.com - How to connect to SQL Server 2005
and that sight has been a great help, but even that doesn't quite explain everything so I can say:

Connection String = Data Source=Server\DB;Initial Catalog=rexamship;
Connect String 1= Connection String + User ID & Password
Connect String 2= Connection String + Use Windows Account

And have it always work. It seems simple enough, but it isn't.
Thanks everyone,
 
Back
Top