Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

Sharepoint 2013 - Query a SQL DB to pull information

On our current .asp intranet site we query information from several SQL DB's such as daily lunch menu, MTD/YTD company sales, open orders, etc.

We are in the process of changing to Sharepoint and would like to pull the same information.   I find questions on how to query the Sharepoint DB but I need to query other DB's

Thanks for any help.

DIM strSQLQuery, strITEM3, strMENUCHANGED, strITEM2
'
%>

 <!--#include file="sql/includes/SQL_SERVER_OR_CAFE_DATABASE.asp"-->


<%
'
'
'END OF SETUP
%>
<center><table width="60%" border="1" cellspacing="3" cellpadding="3">
   <%



strSQLQuery = "SELECT DAILY_MENU.MENU_DATE, MENU_ITEMS.MENU_ITEM AS ITEM1, MENU_ITEMS_1.MENU_ITEM AS ITEM2, MENU_ITEMS_2.MENU_ITEM AS ITEM3, " &_
"DAILY_MENU.SALES_PRICE, { fn DAYNAME(DAILY_MENU.MENU_DATE) } AS [DAY], DAILY_MENU.ID, DAILY_MENU.MENU_CHANGED, DAILY_MENU.CHANGED " &_
"FROM DAILY_MENU LEFT OUTER JOIN MENU_ITEMS MENU_ITEMS_2 ON DAILY_MENU.MENU_ITEM_ID_3 = MENU_ITEMS_2.MENU_ID LEFT OUTER JOIN "&_
"MENU_ITEMS MENU_ITEMS_1 ON DAILY_MENU.MENU_ITEM_ID_2 = MENU_ITEMS_1.MENU_ID LEFT OUTER JOIN MENU_ITEMS ON "&_
"DAILY_MENU.MENU_ITEM_ID_1 = MENU_ITEMS.MENU_ID " &_
"WHERE  (DAILY_MENU.MENU_DATE = { fn CURDATE() }) ORDER BY DAILY_MENU.MENU_DATE"



    	Set MyRS = Server.CreateObject("ADODB.RecordSet")


    	Set MyRS = dli.Execute(strSQLQuery)



    	WHILE NOT MyRS.EOF
    	    %>


		<tr><td width="10%" align="center" valign="middle"><%=UCASE(MyRS("DAY"))%></td>


<%

if MyRS("CHANGED") = "Y" then

%>
				<td width="15%" align="center" valign="middle" bgcolor="#FFFFCC"><%=MyRS("MENU_DATE")%></td>
<%
else
%>
<td width="15%" align="center" valign="middle"><%=MyRS("MENU_DATE")%></td>
<%
End if
%>


		<td width="55%" align="center" valign="middle"><%=MyRS("ITEM1")%>

		<%
						if MyRS("ITEM2") <> "" then
						strITEM2=", " & MyRS("ITEM2")
						else
						strITEM2 = ""
						end if
				%>
        <%=strITEM2%>
		<%
		if MyRS("ITEM3") <> "" then
		strITEM3=", " & MyRS("ITEM3")
		else
		strITEM3 = ""
		end if
		%>
		<%=strITEM3%></td>
		<td width="10%" align="center" valign="middle">$&nbsp;<%=MyRS("SALES_PRICE")%></td>


<%
     MyRS.MoveNext

     WEND

     MyRS.Close
     set MyRS = nothing

%>

Open in new window

0
DMTechGrooup
Asked:
DMTechGrooup
  • 3
  • 2
2 Solutions
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Set MyRS = Server.CreateObject("ADODB.RecordSet")


          Set MyRS = dli.Execute(strSQLQuery)


How MyRS knows which DB to query? From Server connection right?
So you should to connect to others DB as you are connecting to this one but need to change the connection string for access to the correct database.
0
 
DMTechGrooupAuthor Commented:
The DB connection is in the include file

<!--#include file="sql/includes/SQL_SERVER_OR_CAFE_DATABASE.asp"-->

But I do not know how to do this type of thing in SharePoint.  I took a page and added code and all that but is just displayed my code and not run it.  So I don't know where to start.

I am pretty new to SharePoint.
0
 
Jayaraja JayaramanSharepoint Architect ConsultantCommented:
if you wanna use sharepoint list to store and retrieve data then there are couple of ways to do it.
1.linq
2.caml
3.rest webservices,
4.more....
and then for connecting to other databases you can use BCS and external list so you can stay inside sharepoint object model to query and display the list information
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Looks like your problem is how the define a connection to a SQL Server database, right?

Depending on SQL Server version and on the components that you are using you can find plenty of cases in this link http://www.connectionstrings.com/sql-server/

For example, if you are connecting through SQL Server native client to a SQL Server 2008 database with a SQL Server user, this should be the connection string:
Provider=SQLNCLI10;Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

Open in new window


Hope that helps you.
0
 
DMTechGrooupAuthor Commented:
Sorry if I seem frustrating or such.. But does anyone have an example .aspx or something I can look at to see.  Or if I were to show you what .asp I am using you can be more specific how you would accomplish the same thing?
0
 
DMTechGrooupAuthor Commented:
I will try these suggestions and open new if needed.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now