Notification

Icon
Error

Query A Different SQL Server Database - Custom Widget That Will Query A SQL Server Database Other Than The LS DB

Posted: Thursday, June 25, 2015 1:13:00 AM(UTC)
WardD

WardD

Member Original PosterPosts: 2
0
Like
This issue has been solved! Click here to view the solution
Our Technicians use a call ticket application, written in-house, that writes to a SQL Server database apart from the Lansweeper database. When in the Lansweeper UI, I'd like to provide a custom widget that will query the call ticket database for a given asset, and return closed call ticket information. I have added the connection string information to the web.config file, but I'm unfamiliar with how to query within the custom widget .aspx file. Any suggestions would be greatly appreciated Angel

WardD
#1WardD Member Original PosterPosts: 2  
posted: 6/25/2015 2:23:10 AM(UTC)
Would there happen to be a function in the Lansweeper DB class similar to ExecuteDataset that would allow me to specify a connection string?
Daniel.B
#2Daniel.B Member Posts: 1,150  
posted: 6/25/2015 2:18:40 PM(UTC)
You could import System.Data.SqlClient in your aspx file and start a new connection to the external database. This could either happen in the aspx directly or in the code file in the background. The code below is just a rough example.
Code:

...
<%@ Import Namespace="System.Data.SqlClient" %>
...


string connectionString = null;
SqlConnection connection;
SqlCommand command;
string sql = null;
string result = null;

connectionString = @"Data Source=HOSTNAME\INSTANCENAME;" +
@"Initial Catalog=DATABASENAME;User ID=USERNAME;Password=PASSWORD";
sql = @"Your SQL query";

connection = new SqlConnection(connectionString);
try
{
	connection.Open();
	command = new SqlCommand(sql, connection);
	result = command.ExecuteScalar().ToString();
	command.Dispose();
	connection.Close();
}
catch (Exception ex)
{
	result = "No connection to Database";
}

%>

<p>The result is: <%:result%></p>
...

Active Discussions

Lansweeper Report showing only Wi-Fi Devices and MAC addresses
by  Andy.S   Go to last post Go to first unread
Last post: Today at 2:23:24 PM(UTC)
Lansweeper Modifying Purchase Date / Yearly Refresh Report
by  Cripple.Zero   Go to last post Go to first unread
Last post: 5/7/2021 7:06:47 PM(UTC)
Lansweeper Tweak LanSweepers Bios Version Audit to show Last Seen
by  Tyler M.  
Go to last post Go to first unread
Last post: 5/6/2021 8:22:40 PM(UTC)
Lansweeper Patch Volume Across Fleet
by  darren.kimber  
Go to last post Go to first unread
Last post: 5/5/2021 11:29:33 PM(UTC)
Lansweeper Show Date Without Time
by  nhouse24   Go to last post Go to first unread
Last post: 5/4/2021 10:39:43 PM(UTC)
Lansweeper Report of list of assets
by  Carlos Montes  
Go to last post Go to first unread
Last post: 5/4/2021 2:52:15 PM(UTC)