
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2015 02:13 AM
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

Solved! Go to Solution.
Labels:
- Labels:
-
General Discussion
1 ACCEPTED SOLUTION

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2015 03:18 PM
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.
...
<%@ 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>
...
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2015 03:18 PM
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.
...
<%@ 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>
...

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2015 03:23 AM
Would there happen to be a function in the Lansweeper DB class similar to ExecuteDataset that would allow me to specify a connection string?
