Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Christopher Gilmore

Member Since 28 Nov 2010
Offline Last Active Jul 24 2015 12:58 AM
-----

#6145 Netduino + SQL client (maybe System.Data.SqlClient)??

Posted by Christopher Gilmore on 16 December 2010 - 03:35 AM

I took Quiche31's advice and wrote some ASP.NET web services that my computer uses to communicate with the netduino plus. Here is some code... On the netduino side of things.... //Socket to connect to webservice Socket socWebService = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //IP of where to send the request IPEndPoint Desination = new IPEndPoint(IPAddress.Parse("192.168.1.3"), 8081); //Bind to new socket socWebService.Bind(new IPEndPoint(IPAddress.Any, 80)); //Connect to destination socWebService.Connect(Desination); if (socWebService != null) { string request = "Source=" + Source + "&EventTypeID=" + EventTypeID.ToString(); string header = "POST /DoorBuzzerSvc.asmx/LogDoorEvent HTTP/1.1\r\nHost: localhost\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: " + request.Length.ToString() + "\r\n\r\n"; socWebService.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None); socWebService.Send(Encoding.UTF8.GetBytes(request), request.Length, SocketFlags.None); //Check to see if we got data back... if (socWebService.Available > 0) { //Process response byte[] buffer = new byte[socWebService.Available]; int readByteCount = socWebService.Receive(buffer, socWebService.Available, SocketFlags.None); string content = new string(Encoding.UTF8.GetChars(buffer)); //View Response Debug.Print(content); } } socWebService.Close(); And on the WebService Side of things..... in an asmx.vb file <WebMethod()> _ Public Function LogDoorEvent(ByVal Source As String, ByVal EventTypeID As Integer) As Boolean 'Log the ring in a DB Dim DBConnection As New SqlConnection("data source=.;Integrated Security=SSPI;Initial Catalog=DoorBuzzer;") DBConnection.Open() Dim SQLText As String = "INSERT INTO Events (Source, EventTypeID) Values (@Source, @EventTypeID)" Dim SQLCmd As New SqlCommand(SQLText, DBConnection) SQLCmd.Parameters.AddWithValue("@Source", Source) SQLCmd.Parameters.AddWithValue("@EventTypeID", EventTypeID) SQLCmd.ExecuteNonQuery() SQLCmd.Dispose() DBConnection.Close() DBConnection.Dispose() Return True End Function


home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.