Click here to Skip to main content
13,093,184 members (65,610 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to connect to an sql database using the following connection string

Dim strCon As String = "Data Source=DATABASE,2048;Initial Catalog=STUFF;User Id=domain\username; Password=12345678"

when using this i get login failed for domain\username

but if I use

Dim strCon As String = "Data Source=DATABASE,2048;Initial Catalog=STUFF;Trusted Connection=Yes;

then is works fine as i am logged in under my own domain login details while coding.

I need to be able to use my username and password in the connection string as i will be running the application on a different pc under another user. Access to the databases in our company a strictly controlled so I can't get access for the other users.
Is there something else I need in the connection string.

Posted 20-Sep-12 0:44am
Wes Aday 20-Sep-12 6:53am
If you open the database and look at the security, does your username have a security role assigned and access to the "stuff" database?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Yes, need to visit[^].

Have a nice day.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

"Data Source=ServerName;Initial Catalog=DatabaseName;User Id=username; Password=password"

Happy Coding!
johnjsm 20-Sep-12 7:17am
That is what i am already using and its not working
aarti meswania 20-Sep-12 7:19am
you have write - 'Data Source=DATABASE'
it is 'Data Source=ServerName'

and Database name will be assigned to 'Initial Catalog'
aarti meswania 20-Sep-12 7:21am
for example

Data Source=My-PC\SQLEXPRESS;Database=MyDatabase;uid=sa;pwd=sa


Data Source=My-PC\SQLEXPRESS;Initial Catalog=MyDatabase;uid=sa;pwd=sa
johnjsm 20-Sep-12 7:22am
sorry. this is what i have.
"Data Source=ServerName,2048;Initial Catalog=DATABASE;User Id=domain\username; Password=12345678"
aarti meswania 20-Sep-12 7:26am
open sql server copy server-name from sql's login window and paste it after
Data Source=________
from same window username & password
and then your database name
johnjsm 20-Sep-12 7:32am
I can't actually show those details here as its a corporate database
aarti meswania 20-Sep-12 7:37am
you are accessing it successfully using username & password so it is secure
johnjsm 20-Sep-12 7:43am
yes. but its against corporate policy to post information like that
aarti meswania 20-Sep-12 7:51am
no i am not saying that
it means your connection string is working well and you have id & pwd for sql login so, it is a secure sql connection.

you have id password for sql login, still you want more security?
johnjsm 20-Sep-12 8:38am
sorry. my bad. i think my only way around it is to Run As using my login details
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Hi Try this,

Data Source=.\data123;Initial Catalog=DBDesign;Integrated Security=True;Integrated Security=True;User ID=sa;Password=*****" providerName="System.Data.SqlClient"

Happy coding....
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

Hi Please try the below one.

Data Source=ServerName;Initial Catalog=Database Name;User ID=UserID;Password=Password providerName="System.Data.SqlClient" connnectionType="SQL"


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100