User name and password problem

aquamarine

Member
Joined
Feb 23, 2006
Messages
6
Programming Experience
Beginner
I'm Developing my first application in vb 2005 and i am having problems connecting to a sql server database that i have designed. I can't access it because i don't know what my user name and password is for the connection string. Does anybody know where i can find these?
 
From your DBA.... but it also depends on the type of security being used... if Windows security is being used, there is no user/password to lookup. If SQL Security is being used, then you can lookup the user, but for security reasons, you can't just lookup the password.

-tg
 
I have found this and i am using windows security. I left the user Id = and password = to blanks and i am still getting the same error which says that remote access might not be allowed by the default settings. I have found these settings and enabled them and i am still getting the same error. Am i writing the connection string right? Would it be easier if i had sql server security and if so how can i change over to this? When i tried it told me that the user name i used was not associated with a trusted sql sever connection. I really appreciate any help you can give me because i can't figure this out
 
Last edited:
OK, in that case, don't specify the userID or the password... I mean, don't even have them in the conneciton string at all.
Next, you'll want to use Trusted Connection = True along with the rest of the info.
Lastly, visit this link and bookmark it. It'll become your new best friend when it comes to connecting to database and other data stores: http://www.connectionstrings.com/

-tg
 
I have have tried this and now my program is just freezing. Here is the code maybe you can see if i am doing something wrong here

Imports
System.Data.SqlClient
PublicClass Add_Job
Private ConnString AsString

PrivateSub Add_Job_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
ConnString =
"Server=localhost;Database=MyData"

EndSub

PublicSub ReadMyData(ByVal myConnString AsString)


Dim mySelectQuery AsString = "SELECT ProductId, Product FROM Product_lst"
Dim myConnection AsNew SqlConnection(myConnString)
Dim myCommand AsNew SqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As SqlDataReader
myReader = myCommand.ExecuteReader()
' Always call Read before accessing data.
While myReader.Read()
Console.WriteLine((myReader.GetInt32(0) &
", " & myReader.GetString(1)))
EndWhile
' always call Close when done reading.
myReader.Close()
' Close the connection when done with it.
myConnection.Close()


EndSub'ReadMyData


PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

ReadMyData(ConnString)
EndSub


PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
EndSub

End
Class
 
Last edited:
Your connectionstring isn't right.... You need to include Trusted_Connection=True; as part of it... otherwise it doesn't know what kind of security to use....

VB.NET:
PrivateSub Add_Job_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
ConnString = "Server=localhost;Database=MyData;Trusted_Connection=True"

EndSub

-tg
 
Yes, i had tried both with and without Trusted_Connection = True after your second reply. I have even created a new project and created the database again but i still get the same error when i try to open the connection. This is the exact error "sqlException was unhandled: An error has occured while establishing a connection to the server.When connecting to SQL server 2005, this failure may be caused by the fact that under the default setting SQL server does not allow remote connections".
Also i am able to connect to a database no problem if i use the databinding properties of controls so i can't see what the problem here is.
 
Just out of curiosity.... you're trying to login as a Windows user right? By any chance does the windows user you are loggin in as not have a password set? We ran into an issue duruing training where we couldn't connect to our databases either because the Windows logins we were using did not have a password set. Theres's a feature/bug/annoyance that prevents Windows users with no password from being able to connect to SQL databases - note this is a .NET thing as we could connect using the Server Browser, Query Analyzer and Enterprise manager.

Alegedly it's a "security feature"

-tg
 
I did not have a password set on windows but i have put one on it now and i am still getting the same error. Just guessing now, my computer is connected to a wireless router and is also networked with other computers in the house. Could this be causing the problem?
Would it be easier if i set up a user name and password on the database to bypass this problem? If so, how can i do this? This is a really annoying error because i am doing everything according to the books i have and stuff i have looked up on the internet, by the way i read your articles about ADO .net and found them very good and to the point, keep it up.
 
Back
Top