Results 1 to 24 of 24

Thread: [2005 Express] Simple SQLServer 2000 Connection Error

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Angry [2005 Express] Simple SQLServer 2000 Connection Error

    I'm trying to connect to a SQLServer 2000 database.
    This is my code:

    On Form_Load i'm calling the Conect function.
    On Form_Leave i'm calling the Disconect function.

    Code:
      Public CNN As New SqlClient.SqlConnection
        Public rs As New SqlClient.SqlDataAdapter
    
        Public Const ID_DB As String = "GesProj"
        Public Const server As String = "TURION\PRIMAVERA"
        Public Const user As String = "SA"
        Public Const Password As String = "SA"
    
        Public Sub Conect()
            Try
                CNN.ConnectionString = "Data Source=" & server & ";Initial Catalog=" & ID_DB & ";Persist Security Info=True;User ID=" & user & ";Password=" & Password
                CNN.Open()
                Exit Sub
    
            Catch err As Exception
                MessageBox.Show("Erro: " & err.Message, "Sem conexão", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Clipboard.Clear()
                Clipboard.SetText(err.Message)
            End Try
        End Sub
    
        Public Sub Disconect()
            Try
                CNN.Close()
                CNN = Nothing
                Exit Sub
            Catch err As Exception
                MessageBox.Show("Erro: " & err.Message, "Sem conexão", MessageBoxButtons.OK, MessageBoxIcon.Error)
               
            End Try
        End Sub
    When Conect function is called I get this error:

    An error has occurred 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 settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    Need help, please.

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Hi.
    Try to use Windows Authentication on connection string instead of SQL Authentication to see if you can connect.
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    SQL Server Authentication is set to "SQL and Windows" but I've tried to do this connection in vb6 and everything works great.
    What do you think?

    Thank you.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    In your Disconect sub, you set CNN = Nothing... So any subsequence call of your Conect and Disconect sub will fail.

  5. #5

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Why do you say that?
    The Disconect function is only called when the program closes.

  6. #6
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    So, you are opening a connection at startup and then closing it on close. This was pretty common in VB6 apps (At least where I work) but we have moved to opening and closing connections as needed since we moved to .net. I personally think it is a better method and perhaps you should think about switching to such a method.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  7. #7

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Thanks for the advice, but that is not a big problem for me, now. What I want to know is: why do I get the error?

    As I said earlier, I can connect to DB throw vb6, but not with vb2005 Express.
    What am I doing wrong?

    Thank you

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Quote Originally Posted by RS_Arm
    Why do you say that?
    The Disconect function is only called when the program closes.
    You're not calling the Disconect sub in Form_Leave event, are you? You should notice that Form_Leave event is not the same as Application.Exit() or Me.Close()
    On Form_Load i'm calling the Conect function.
    On Form_Leave i'm calling the Disconect function.

  9. #9

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Well, yes... I'm moving from vb6 to .net. Shouldn't be doing this?
    Although my mistake, I removed the disconect function, and I still got the same error.

    (PS:Thanks for the tip! )

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    I'm dizzy from watching everyone dance around the real problem. It doesn't matter where the disconnect is.... the OP cant' even connect in the FIRST PLACE.

    Are you sure the connection string is right? Normally, the server is just the computer name.
    Also the reason for the error is in the message. The server is refusing remote connections. If you open up Enterprise Manager, right-click the server entry... select properties... goto the Connections tab... there should be a check box that allows you to turn on/off remote connecitons. Make sure it's on.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Everything is right in SQL, the option "Allow other SQL..." is checked, the maximum user connections is set to unlimited.
    What is strange is that I can do a connection from VB6.
    And I think that the vb2005 code is right.

  12. #12
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Double check your connection string and make sure it's correct.
    You can look it up here http://www.connectionstrings.com/?carrier=sqlserver

  13. #13

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Still nothing...
    My connection string is correct. I've also created another user with administrator privileges.

    What should I do next?

    Thank you

  14. #14
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    I use a differnt style connection string then you, perhaps it may work, hell, can't hurt to try it right

    Code:
    connString = "Server=" & serverName & ";Database=" & Database & ";User ID=" & userID & ";Password=" & pass & ";Trusted_Connection=False"
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  15. #15

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    bmahler, I've used you example and error persists!!
    I don't know what else to do!!

  16. #16
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    What line is erroring? is it con.open?
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  17. #17

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Yes.

  18. #18
    Lively Member
    Join Date
    Mar 2007
    Location
    ZA
    Posts
    65

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Hi

    I also experienced this error and wound up banging my head so hard that I had a head ache for 3 days. For the life of me I cannot remember the solution and I cannot immediately access the project as I changed jobs and I am working mainly with oracle now. I will take a look through my archives if I get a hold of them.

    I do seem to remember something about messing a whole lot around in SQL and then discovering something about the default user names and passwords not being activated or something like the other.

    Have you tried creating a new user name and password and also specifying what tables the user can access?

  19. #19

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    After very long time of search, vb.net express only can connect to local databases. So, even if my computer is named Turion, I will not be able to open it (I think).
    Any reply is welcome

  20. #20
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Wait a minute... nononononono.... that's an incorrect statement. The Express IDE can only connect to local databases... but connecting through code, that works just fine, there's no limitations there.

    Looking back at your code, however, I think your server name is wrong. What is "Turion", and what is "PRIMAVERA"? You should be just using the NAME of the server, nothing more, nothing less. The only other time you should have anything else with it is IF, and ONLY IF, you have MORE THAN ONE SQL instance on a machine. If there is only one instance of SQL Server running on the machine, then ONLY THE SERVER NAME is needed.

    Example, here at the office, we only have SQL 2000 installed on our server. So to connect, we simply use jsut the server name "svrSQLServer".

    At home, I have both SQL2000 and SQL2005 running, so each one gets a name for each of the instance, depending on which one I want to connect to: "myMachine\SQL2000" and "myMachine\SQL2005"

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  21. #21

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Turion is the name of the server (yes, it's a laptop!!) and PRIMAVERA is an instance of SQL.
    What do you think about this?? Strange, isn't it?

  22. #22
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Add "IntegratedSecurity=False;" to your connection string....(I think I spelled that right, Integrated Security maybe two words.)

    And I know this is going to sound like a strange question, but sometimes it's those little things, but and you are on the same network where the server is, correct? Strike that.... I see now, the SQL Server is local.... try this:

    .\PRIMAVERA as the server name... if that doesn't work try (local)\PRIMAVERA.

    Lastly, can you connect to the instance/database using something like SQL Management Studio?

    -tg

    edit - it's not as strange as it sounds.... I've actually come up against this before with a client... gawd those were some long nights.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  23. #23

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    Everything that u said is right but (there is always a 'but'...) I've tried all your suggestions and still got the same error.
    I can access to database using SQL Enterprise Manager and Query Analyzer.
    As i said in one of the firsts posts, I can even access to db using vb6.

    I don't know if it may be relevant but I'm using WnXP x64.

    Thank for your attention

  24. #24

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005 Express] Simple SQLServer 2000 Connection Error

    (techgnome, ff you don't mind, could you see my post on vb6 based on ActiveX EXE?
    This (SQL conn) is not (Now) my ultimate project in my chain of priorities.)
    http://vbforums.com/showthread.php?t=486105)
    Thank you once again.

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