Results 1 to 25 of 25

Thread: [RESOLVED] sql connection string

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Resolved [RESOLVED] sql connection string

    Hi gurus

    I am using the following connection string to connect to a sql server on my network but having all kind of problem

    here is the connection string

    osqlconn.connectionstring="server=xxx.xxx.xxx.xxx,1433;" &"Database=LOS;" & "Integrated security=SSPI"

    I dont know if the problem is that there is no ";" at the last parameter like the others but I get the following error that shows in the file

    I hope someone can help me on this

    Thanks a bunch
    Attached Images Attached Images  

  2. #2
    Fanatic Member sridharavijay's Avatar
    Join Date
    Sep 2002
    Location
    http://www.vijaysridhara.in
    Posts
    589

    Re: sql connection string

    From the error message it appears like
    1) Your server is not accessible (a ping to server will help)
    Or
    2) If accessible, it is not configured to be not accessible from other then Local host. So it needs some configuration settings on the server so that the userid connecting to it can connect to it from remote systems.
    This is true with respect to any database system as far as I know.
    Hope this helps in fixing your issue


    Regds
    Vijay S

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    S.


    Thanks for jumping in on this, I think is hard all about this connection strings

    1) I can ping the server fine, with no problem
    2) I went and check the properties on the sqlserver, what should I be looking for in order to double check the sql server is ready to accept remote connection.

    3) is this the right connection string for sql server 2000?? maybe I have the connection string all worng.

    Thanks a bunch

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: sql connection string

    Try a test project with this. Fill in the "xxxxxxxx" as applicable
    vb.net Code:
    1. Imports System.Data.SqlClient
    2.  
    3. Public Class Form1
    4.  
    5. Private myConnection As SqlConnection
    6.  
    7.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    8.        
    9.         myConnection = New SqlConnection("Integrated Security=SSPI;" _
    10.         & "Persist Security Info=False;Initial Catalog=xxxx; " _
    11.         & "Data Source=xxxxxxxxxx")
    12.         myConnection.Open()
    13.     End Sub
    14.  
    15. End Class

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    hack

    do I need an & between Persist security and Initial catalog?

    Thanks

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: sql connection string

    NO the & is just used for string concatination here
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    gary

    so there should be no & within the string, is that what you are saying.

    Thanks

  8. #8
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: sql connection string

    Yes that is what I am saying.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: sql connection string

    To clarify, your original code:
    Code:
    osqlconn.connectionstring="server=xxx.xxx.xxx.xxx,1433;" & "Database=LOS;" & "Integrated security=SSPI"
    ..does exactly the same as this:
    Code:
    osqlconn.connectionstring="server=xxx.xxx.xxx.xxx,1433;Database=LOS;Integrated security=SSPI"
    ...and this too:
    Code:
    osqlconn.connectionstring="s" & "e" & "r" & "v" & "e" & "r" & "=xxx.xxx.xxx.xxx,1433;" & "Database=LOS;" & "Integrated security=SSPI"
    That is because one " ends a string, & concatenates (joins) it to something, and the next " starts another string.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    Thanks a bunch

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    Gurus

    Thanks for battling with me here,

    I test connection and the string connection does not work

    I get an error

    Login Failed for user'(null)'.Reason:not associated with a trsuted Sql Server Connection".

    any help ,
    Thanks a bunch

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    Any other ideas gurus,
    please keep battling with me on this I would really like to connect to the sql server, instead of going the access 2003 route.

    Thanks again

  13. #13
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: sql connection string

    That mean that you are not in a domain. If that is so then you need to supply a username and password (sql log in). What version of SQL Server are you using.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    Gary

    Thanks a bunch really

    1) I am using Sql 2000.

    2) but I am in the domain.

    This string connection gives people headaches


    Thanks a bunch

  15. #15
    Junior Member
    Join Date
    Jul 2010
    Posts
    28

    Re: sql connection string

    Quote Originally Posted by GUARO View Post
    Gurus

    Thanks for battling with me here,

    I test connection and the string connection does not work

    I get an error

    Login Failed for user'(null)'.Reason:not associated with a trsuted Sql Server Connection".

    any help ,
    Thanks a bunch
    Hi.

    The error means that you need to create a user in the server so that your application can use it to connect to the database and use it.

    So first step is create a new user on the server, add privileges/permissions, and finally update your connection string, so it looks something similar to this :

    Code:
    osqlconn.connectionstring="server=xxx.xxx.xxx.xxx,1433;Database=LOS;Persist Security Info=False;User ID=MyUser;Password=MyPassword"
    Simply adapt the "myuser" and "mypassword" with the ones of the created user, also, its up to you if you want to have the password on the connection string or not.

  16. #16
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: sql connection string

    First can you connect to the database using the Query tool with Windows auth?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    Gurus

    Thanks thanks thanks for all your help

    Z.

    That is what is driving me crazy, I have added in the security->loging a user to this Database "LOS"

    Gary
    which query tool do you recommend.

    I am very new to this so I realy thanks for your patience.
    Thanks a bunch gurus

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    hi gurus

    I followed Gary steps based on Ze post and here is what I found

    Sql server and Ws are in to different Vlan

    sql Server is on 192.xxx.xxx.xxx and WS are on 10.xxx.xxx.xxx, I can ing the server in which the sql server resides but for some reason I can not connect to the sql server instance using the query tool from a WS(10), I went to one of the server(192) and use the same query tool and had no problem getting to the datbase an therefore the table.

    Does this mean I am scr.... or is there a way to deal with this, I change the string connection to be use to a TPC/IP one but with no avail.

    what else can I do in this case.

    thanks a bunch for any help

  19. #19
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: sql connection string

    If the two machines are not in the same domain. Then you will need to create a SQLServer User login and give that user permissions on the database you want. Then instead of connection with Intergrated Security you supply the user name and password to use.

    I can connect to differnt IP statring 10.10.xx.xxx and the server is on 15.x.x.xxx as long as my windows longin in vailid in both domains I can use Intergrated Security (as long as I am in a group) that has rights on the server any way
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    Gary

    Here is the nightmare, well at least for me

    ws are on the 10.xx.xx and server is on the 192, both machines are on the same domain as of now, but all traffic is allow from 10 to 192 through our Cisco vlan router, that is why 10 can see 192 but for some reason this does not work for Sql server it does not like the 10 connecting to 192,

    I can ping from 10 to 192 and I can ping from 192 to 10 with no problem but again I cant see sql from 10.

    what can I do
    Thanks again

  21. #21
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: sql connection string

    Have you created a login inside SQL Server, and tried using that in the connection string (as in Zeth643's example)?

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    S/ze

    Yes I think I did

    I went to sql server ena expanded all untill find security, then I add a user and give permission and security for the LOS database, I am using the username and password to try to connect to it, also I am the system admin in the role.

    I am missing something

    thanks

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    gurus

    here is an update

    1) I went into the server(192) and created a user within the server manage account
    2) I went into security->login and add the local user to the database
    3) I set the auth to sql server and windows
    4) I have restart the sqlserver service everytime I make a change
    5) I have used the following string connection

    Code:
    "osqlconn = New SqlConnection("integrated Security=SSPI;Persist Security Info=False;Initial Catalog=LOS;Data source=192.xxx.x.xx,1433")"]
    also the following
    Code:
    "osqlconn.ConnectionString = "server=192.xxx.x.xx,1433;Database=LOS;Persist Security Info=False;User ID=susername;Password=xxxxxxx;"
    and last trying to use a TCP/IP string connection

    Code:
    "osqlconn.ConnectionString = "data source=192.xxx.x.xx,1433;network library=dbmssocn;initial catalog=LOS;user ID=username;password=xxxxxx"
    But all I get is

    login faild for user "username"

    shoudl I be using the full username server\username or domain\username?

    maybe the problem is been in two different subnet

    thanks for battling with me here ,hope you dont give up as of yet.

    Thanks a bunch
    Last edited by GUARO; Mar 2nd, 2011 at 10:03 PM.

  24. #24
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: sql connection string

    The user should not have a server/domain, because it is supposed to be just an SQL Server user, not based on a Windows user.

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: sql connection string

    gurus


    Yeahhhhhhhhhhhhhhhhhh yeahhhhhhhhhhhhhh

    I got in, thanks
    zrid,hack,gary,zethand SI,for not giving up, thanks a bunch gurus, I realy appreciate all your help on this one and other posts.

    Thanks again

    yeahhhhhhhhhhhh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width