SQL server using OleDBConnection with Visual studio .net

  • Thread starter Thread starter Dhruva Gopal
  • Start date Start date
D

Dhruva Gopal

Hi,
I am seeing a really weird problem with SQL server
databases and using OleDBConnection in Visual studio .net
environment. See the basic code below:

String connStr
= "Provider=SQL;UID=uname;PWD=pwd;Addr=xxx.xxx.xxx.xxx;Data
Source=DBNAME;Connection Timeout=30";

OleDbConnection dbConn = new OleDbConnection(connStr);
dbConn.Open();

Now I have another Database in the sameserver called
called, say DBNAME2, with the same username as password as
dbuser specified above(that is, uname and pwd). In SQL
server that user defaults to database DBNAME. Now when I
open a new connection with the same connection string as
above except for the Data Source, which now points to
DBNAME2, and I query this database (DBNAME2), I get data
from DBNAME, inspite of giving the data source name as
DBNAME2. The only way I can workaround this issue, is to
create a new user, and give that user permissions to this
second database DBNAME2.

The reason for having 2 databases on the same system and
mirroring each other is to compare the two databases (they
have the same tables and fields) - we are trying to
compare the data in the tables.

Why is it that with SQL server it is defaulting to the
default database specified for that user, inspite of
giving the database name in the connection string.

Thanks
Dhruva
 
Thus spake Dhruva Gopal:
Why is it that with SQL server it is defaulting to the
default database specified for that user, inspite of
giving the database name in the connection string.

Does the problem exist when you use a SqlConnection?
 
-----Original Message-----
Thus spake Dhruva Gopal:


Does the problem exist when you use a SqlConnection?

--

Yes it works - I changed the connection string to use
database instead of data source and that seems to solve
the problem with using the default DB for that user.

Thanks for your time.
 
Back
Top