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 End of Life Asset Report
by  DJ Bradley   Go to last post Go to first unread
Last post: Yesterday at 7:26:26 PM(UTC)
Lansweeper Translation settings not saved
by  Brandon  
Go to last post Go to first unread
Last post: Yesterday at 2:10:22 PM(UTC)
Lansweeper Combobox translation
by  sneagele   Go to last post Go to first unread
Last post: Yesterday at 2:03:45 PM(UTC)
Lansweeper Freelance for Lansweeper Deploy?
by  Brandon  
Go to last post Go to first unread
Last post: 5/7/2021 6:32:21 PM(UTC)
Lansweeper Installation issues
by  Richie_Rich   Go to last post Go to first unread
Last post: 5/6/2021 11:29:09 PM(UTC)
Lansweeper Cloud relay data stored time
by  Richie_Rich  
Go to last post Go to first unread
Last post: 5/6/2021 11:14:42 PM(UTC)
Lansweeper Custom attributes from AD
by  dhoward   Go to last post Go to first unread
Last post: 5/6/2021 11:10:45 PM(UTC)
Lansweeper User View Customization
by  DarkOne77  
Go to last post Go to first unread
Last post: 5/6/2021 10:50:30 PM(UTC)