Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.net application not connectining to SQL Server

Status
Not open for further replies.

kylua

Technical User
Sep 30, 2002
199
GB
Hello All
I have created a vb.net program that needs to connect the local instance of SQL Server in order to create a SQL Server database.
I have created a test program where the code is simply:
Code:
Public ConnectionString As String
    Public reader As SqlDataReader = Nothing
    Public conn As SqlConnection = Nothing
    Public cmd As SqlCommand = Nothing
    Public sql As String = Nothing
    Sub CreateDB()
        ' Create a connection
        ConnectionString = "Integrated Security=SSPI;Initial Catalog=;Data Source=Localhost;"
        conn = New SqlConnection(ConnectionString)
        ' Open the connection
        conn.Open()
        conn.Close()
        MsgBox("Result!!")
	end sub
Works fine on the development computer, including when actually installed onto the development computer from published files.
When deploying on another computer it will download and install SQL Server Express if it is not already installed.
But won't access the database! Simply crashes on the conn.open line. Declaring the database is not accessible.

This includes on a server where I run ASP.NET apps which connect to a SQL Server database all the time.
Tried specifying the master database, again, worked locally but not on another computer.
Pipes is enabled, everything is enabled!
Tried a different connection string:
"Server=Localhost;Database=;Trusted_Connection=True;"
No difference.

Currently using a Win 7 machine, the code won't work on an XP machine I have but it DID work on that machine before the hard drive went kaflooie and everything was reinstalled.
Testing the installation on a server 2003 machine, and another xp machine. Both failed.

Added the instance name in:
"Server=localhost\SQLEXPRESS;Database=;Trusted_Connection=True;"
Same happened.

I am totally lost here, has anyone any ideas?

Many thanks
 
What's the actual error message that is returned from SQL when you try and connect.

Denny
MVP
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / SQL 2005 BI / SQL 2008 DBA / SQL 2008 DBD / SQL 2008 BI / MWSS 3.0: Configuration / MOSS 2007: Configuration)
MCITP (SQL 2005 DBA / SQL 2008 DBA / SQL 2005 DBD / SQL 2008 DBD / SQL 2005 BI / SQL 2008 BI)

My Blog
 
It's not actually SQL yet,
Code:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

But it's not 'instance specific'!!

Thanks.
 
Are you sure that the instance has started? Have you verified that the instance is named correctly?

Denny
MVP
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / SQL 2005 BI / SQL 2008 DBA / SQL 2008 DBD / SQL 2008 BI / MWSS 3.0: Configuration / MOSS 2007: Configuration)
MCITP (SQL 2005 DBA / SQL 2008 DBA / SQL 2005 DBD / SQL 2008 DBD / SQL 2005 BI / SQL 2008 BI)

My Blog
 
Are you sure that the instance has started? Have you verified that the instance is named correctly?

K2
Yes. This fails even when SQL Server Management studio is connected to the instance.
Que? There is no instance named, just references 'localhost' which should be absolutely generic to the local instance on all servers/computers. I thought.
 
When you connect to localhost that will connect to the default instance on the local machine. If the instance is a named instance you need to specify the name in the connection string "localhost\instancename".

Denny
MVP
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / SQL 2005 BI / SQL 2008 DBA / SQL 2008 DBD / SQL 2008 BI / MWSS 3.0: Configuration / MOSS 2007: Configuration)
MCITP (SQL 2005 DBA / SQL 2008 DBA / SQL 2005 DBD / SQL 2008 DBD / SQL 2005 BI / SQL 2008 BI)

My Blog
 
On a different computer in a different office on a different job but if I recall correctly I have successfully connected with 'Localhost/SQLEXPRESS' and just 'Localhost' on the development computer and both failed on the installation test computer. Where the local instance is 'SQLExpress'.

Currently given up on using SQL Express and am using Access simply becos I had hit a brick wall on this and wanted to get on. But I would prefer to use SQL Express if I can make sure it will work.

I haven't tested this on a computer that doesn't have Access installed but I understand the Jet database engine is native to Windows so there shouldn't be a problem?
 
Look in the list of services. Look for something that starts with SQL Server. If the service name is "SQL Server (SQLEXPRESS)" then the instance name is SQL Express. If it is "SQL Server (MSSQLSERVER)" then it is the default instance. If you don't see this listed then the service isn't installed.

I believe that to use JET you'll have to distribute some stuff.

Denny
MVP
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / SQL 2005 BI / SQL 2008 DBA / SQL 2008 DBD / SQL 2008 BI / MWSS 3.0: Configuration / MOSS 2007: Configuration)
MCITP (SQL 2005 DBA / SQL 2008 DBA / SQL 2005 DBD / SQL 2008 DBD / SQL 2005 BI / SQL 2008 BI)

My Blog
 
I knew the instance was called SQLEXPRESS on the target machines, both of them. That's not the problem.

I'll need to test the new Access system to be sure, (I previously thought it was all sorted with SQL Express!), but I'm reasonably confident that it doesn't require extras to be installed.

Still love to get SQL Express installed but spending days researching and trying out various configs with nothing to show for it is not conducive to getting on with my new 'boss'.
 
Can you telnet from the server to the TCP port that the SQL Server is listening on?

Denny
MVP
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / SQL 2005 BI / SQL 2008 DBA / SQL 2008 DBD / SQL 2008 BI / MWSS 3.0: Configuration / MOSS 2007: Configuration)
MCITP (SQL 2005 DBA / SQL 2008 DBA / SQL 2005 DBD / SQL 2008 DBD / SQL 2005 BI / SQL 2008 BI)

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top