Hello
I was told that it was a REALLY bad idea to send SQL queries directly over the Internet. That's why I'm here.
I'm trying to make a web service to forward SQL queries from a VB.net plugin to my SQL server and return the result, but have little idea of how to attack this. Have been searching the web and have made something that look like it can work as a web service:
The simple WebService.asmx file (not made in .Net!) contains the following:
<%@ WebService Language="VB" Class="MoodAndStyle" %>
Imports System.Web.Services
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class MoodAndStyle
Private Function GetDataSet(SQLQuery as String) as DataSet
'1. Create a connection
Dim SQLconn as New SqlConnection("Data Source=10.0.0.5;Initial Catalog=Mood;User Id=moodDBUser;Password=test;")
'2. Create the command object, passing in the SQL string
Dim command as New SqlCommand(SQLQuery, SQLconn)
SQLconn.Open()
'3. Create the DataAdapter
Dim dataAdapter as New SqlDataAdapter()
dataAdapter.SelectCommand = command
'4. Populate the DataSet and close the connection
Dim myDataSet as New DataSet()
dataAdapter.Fill(myDataSet)
SQLconn.Close()
'Return the DataSet
Return myDataSet
End Function
<WebMethod()> Public Function GetArtists() as DataSet
Return GetDataSet("SELECT * FROM Artist")
End Function
End Class
I need to return the dataset from the SQL server. I read that I could use a web service proxy, but don't really want to complicate this. I had a hard enough time making the actual plugin in VB.net...
Are there anyone that could tell me what kind of stuff I need to make this work For now I would just like to push a button to return the dataset. I know how to extract the data from the dataset. But thats about it.
- Carl