Click here to Skip to main content
15,895,462 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello All,

I am trying to create a simple little program for my company that will allow management people to input a computer name into a text hit process, and it query our WMI database and pull the software information for that computer.

CODE:
VB.NET
Dim ConnectionString As String = "Data Source=LANSWEEPER\SQLEXPRESS;Initial Catalog=lansweeperdb;User ID=sa;Password=MYsaPASSWORD;Connect Timeout=30"
 
Dim Connection As New System.Data.SqlClient.SqlConnection(ConnectionString)
 
Dim command As New System.Data.SqlClient.SqlCommand("SELECT a.Username, a.ComputerUnique, c.softwareName, c.softwareVersion, c.SoftwarePublisher FROM dbo.tblComputers a RIGHT JOIN dbo.tblUsers b ON b.Computername = a.Computername JOIN dbo.tblSoftware c ON c.Computername = a.ComputerName WHERE a.ComputerUnique = CORP\" & My.Resources.ComputerName & "\1", Connection) 


If I just have the one '\' in the Data Source I get a syntax error, and if I have two '\' i get that program couldn't find the instance.

The SQL server is configured correctly because we have a web site for the Help Desk to interface with the system. The connection string is mostly if not all from the web.config file.

Any assistance would be great.

Thanks in advanced

Tim
Posted
Updated 8-Mar-11 10:56am
v3

If LANSWEEPER is a server name, then you will need to update your connection string like this:
VB
Dim ConnectionString As String = "Data Source=\\\\LANSWEEPER\\SQLEXPRESS;Initial Catalog=lansweeperdb;User ID=sa;Password=MYsaPASSWORD;Connect Timeout=30"
 
Share this answer
 
Comments
Espen Harlinn 8-Mar-11 16:23pm    
Nicely spotted - my 5
Tim DeCenso 10-Mar-11 7:52am    
Thank you Marcus for your response

I have changed my code to the following:

<pre>
Private Sub Test()
Dim ConnectionString As String = "Data Source=\\\\LANSWEEPER\\SQLEXPRESS;Initial Catalog=lansweeperdb;User ID=sa;Password=MYsaPASSWORD"
Dim Connection As New System.Data.SqlClient.SqlConnection(ConnectionString)
Dim command As New System.Data.SqlClient.SqlCommand("SELECT c.softwareName, c.softwareVersion, c.SoftwarePublisher FROM dbo.tblComputers a JOIN dbo.tblSoftware c ON c.Computername = a.ComputerName WHERE a.ComputerUnique = CORP\" & My.Resources.ComputerName & "\1", Connection)
Dim dt As New DataTable
Dim adpt As New Data.SqlClient.SqlDataAdapter(command)
Try
Connection.Open()
adpt.Fill(dt)
DataGridView1.DataSource = dt
Catch ex As Exception
MsgBox(ex.ToString)
Finally
Connection.Close()
End Try
End Sub</pre>

I still get a connection error on Line 21 which is the connection.open() line.

The exact error is:

System.Data.SqlClient.SqlException (0x80131904): 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: SQL Network Interfaces, error: 25 - Connection string is not valid)
Espen Harlinn 10-Mar-11 9:44am    
The error message probably gives you a strong hint: Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

You may use "SQL Server Configuration Manager" to enable TCP/IP and possibly Named Pipes if you want to use that. Use the SQL Server Network Configuration node to configure the server instance.
I figured out the problem.

It was because my database resided on a Express edition and the database size is 0.18 mb of exceeding its file size limit of the 4096 mb.

So every time it tried to connect it exceed the file size limit and SQL Express would put the ax down on my connection.

Which is weird because I can log in through Toad.

Anyways, thanks for the help marcus.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900