Home All Groups Group Topic Archive Search About

Best way to communicate from Desktop to SQL DB

Author
30 Nov 2006 7:36 AM
Anil Gupte
Hi All:

I am looking for general directions on "the right way" to do something,
which is very critical to my application.

I want to communicate with a SQL server database on a Windows Server (in the
future it could be a Linux MYSQL server, but I don't know for sure).  My
application is a desktop application and at various times it may need to
communicate with the server to select, update records etc.

Now the question is, should I build ASP pages which perform the queries on
the server and have the desktop application read the pages and parse them?
If so how?  Are there any samples (I have done something similar before in
VB 6.0 where I embedded IE in the app and "Screen-scraped").

Or should I communicate with SQL queries directly with the server?  If so
how?  Again, any tutorials etc online would help.

Thanx,

Author
30 Nov 2006 7:55 AM
RobinS
You should communicate with the database directly, not through
ASP pages.

Here's an example I have posted before. You can probably find
gazillions others by searching these newsgroups from google groups.
This one opens the database, reads the Product table, then
iterates through it and shows the results.

Dim ds As DataSet
'open the connection
'DBConnectionString is in the Project Settings
Using cnn As New SqlConnection(My.Settings.DBConnectionString)
    cnn.Open()

    'define the command
    Dim cmd As New SqlCommand
    cmd.Connection = cnn
    cmd.CommandText = "SELECT * FROM Product"
    'define the data adapter and fill the data table
    Dim da As New SqlDataAdapter(cmd)
    ds = New DataSet
    da.Fill(ds, "Product")
End Using

For Each dr As DataRow In ds.Tables("Product").Rows
    Dim ProductID As Integer = CType(dr.Item("ProductID"), Integer)
    Dim ProductName As String = dr.Item("ProductName").ToString
    Dim ProductNumber As String = dr.Item("ProductNumber").ToString
    'Dim Price As Nullable(Of Decimal)
    'If .Item("Price") IsNot DBNull.Value Then
    '    Price = CType(.Item("Price"), Decimal)
    'End If
    Dim Description As String = dr.Item("Description").ToString
    'Dim ProductType As Integer = CType(.Item("ProductType"), Integer)
    'Dim StockType As String = .Item("StockType").ToString
    Console.WriteLine(String.Format("ProductID {0}, " & _
      "ProductName {1}, {2}ProductNumber {3}, " & _
      "Description {4}", ProductID, ProductName, _
      ControlChars.CrLf, ProductNumber, Description))
Next

Robin S.
-------------------------------------

Show quoteHide quote
"Anil Gupte" <anil-l***@icinema.com> wrote in message
news:%23utT3IFFHHA.4080@TK2MSFTNGP02.phx.gbl...
> Hi All:
>
> I am looking for general directions on "the right way" to do something,
> which is very critical to my application.
>
> I want to communicate with a SQL server database on a Windows Server (in
> the future it could be a Linux MYSQL server, but I don't know for sure).
> My application is a desktop application and at various times it may need
> to communicate with the server to select, update records etc.
>
> Now the question is, should I build ASP pages which perform the queries on
> the server and have the desktop application read the pages and parse them?
> If so how?  Are there any samples (I have done something similar before in
> VB 6.0 where I embedded IE in the app and "Screen-scraped").
>
> Or should I communicate with SQL queries directly with the server?  If so
> how?  Again, any tutorials etc online would help.
>
> Thanx,
> --
> Anil Gupte
> www.keeninc.net
> www.icinema.com
>
>
Author
30 Nov 2006 9:27 AM
Anil Gupte
Thanx, but the critical step that I do not know how to do is to connect to
the remote SQL Server, in other words, how do I create a connection string
to a remote server (I know the URL and IP address).  Do I need to make any
changes to the remote SQL server?

Thanx,
Show quoteHide quote
"RobinS" <RobinS@NoSpam.yah.none> wrote in message
news:kNKdnV9vhrb_E_PYnZ2dnUVZ_hmdnZ2d@comcast.com...
> You should communicate with the database directly, not through
> ASP pages.
>
> Here's an example I have posted before. You can probably find
> gazillions others by searching these newsgroups from google groups.
> This one opens the database, reads the Product table, then
> iterates through it and shows the results.
>
> Dim ds As DataSet
> 'open the connection
> 'DBConnectionString is in the Project Settings
> Using cnn As New SqlConnection(My.Settings.DBConnectionString)
>    cnn.Open()
>
>    'define the command
>    Dim cmd As New SqlCommand
>    cmd.Connection = cnn
>    cmd.CommandText = "SELECT * FROM Product"
>    'define the data adapter and fill the data table
>    Dim da As New SqlDataAdapter(cmd)
>    ds = New DataSet
>    da.Fill(ds, "Product")
> End Using
>
> For Each dr As DataRow In ds.Tables("Product").Rows
>    Dim ProductID As Integer = CType(dr.Item("ProductID"), Integer)
>    Dim ProductName As String = dr.Item("ProductName").ToString
>    Dim ProductNumber As String = dr.Item("ProductNumber").ToString
>    'Dim Price As Nullable(Of Decimal)
>    'If .Item("Price") IsNot DBNull.Value Then
>    '    Price = CType(.Item("Price"), Decimal)
>    'End If
>    Dim Description As String = dr.Item("Description").ToString
>    'Dim ProductType As Integer = CType(.Item("ProductType"), Integer)
>    'Dim StockType As String = .Item("StockType").ToString
>    Console.WriteLine(String.Format("ProductID {0}, " & _
>      "ProductName {1}, {2}ProductNumber {3}, " & _
>      "Description {4}", ProductID, ProductName, _
>      ControlChars.CrLf, ProductNumber, Description))
> Next
>
> Robin S.
> -------------------------------------
>
> "Anil Gupte" <anil-l***@icinema.com> wrote in message
> news:%23utT3IFFHHA.4080@TK2MSFTNGP02.phx.gbl...
>> Hi All:
>>
>> I am looking for general directions on "the right way" to do something,
>> which is very critical to my application.
>>
>> I want to communicate with a SQL server database on a Windows Server (in
>> the future it could be a Linux MYSQL server, but I don't know for sure).
>> My application is a desktop application and at various times it may need
>> to communicate with the server to select, update records etc.
>>
>> Now the question is, should I build ASP pages which perform the queries
>> on the server and have the desktop application read the pages and parse
>> them? If so how?  Are there any samples (I have done something similar
>> before in VB 6.0 where I embedded IE in the app and "Screen-scraped").
>>
>> Or should I communicate with SQL queries directly with the server?  If so
>> how?  Again, any tutorials etc online would help.
>>
>> Thanx,
>> --
>> Anil Gupte
>> www.keeninc.net
>> www.icinema.com
>>
>>
>
>
Author
30 Nov 2006 4:12 PM
roader
The easiest way to create a connection string is to create an empty
file with .udl extension

doubleclick on it, u will get a wizard to create and test connection
string
once u are finished open the same file with notpad ....Connection
string will be there
Author
1 Dec 2006 4:48 PM
Anil Gupte
That is a great tip!  Thanx, although I have not got it to work yet with my
remote SQL server - working on it.

Show quoteHide quote
"roader" <roade***@gmail.com> wrote in message
news:1164903142.948834.96990@16g2000cwy.googlegroups.com...
> The easiest way to create a connection string is to create an empty
> file with .udl extension
>
> doubleclick on it, u will get a wizard to create and test connection
> string
> once u are finished open the same file with notpad ....Connection
> string will be there
>
Author
30 Nov 2006 4:45 PM
rowe_newsgroups
Here's two sites that may help:

Connecting via ADO and ADO.Net with VB.Net and C#
http://support.sas.com/ctx/samples/index.jsp?sid=817

And for the connection strings:
http://www.connectionstrings.com/

Thanks,

Seth Rowe


Anil Gupte wrote:
Show quoteHide quote
> Thanx, but the critical step that I do not know how to do is to connect to
> the remote SQL Server, in other words, how do I create a connection string
> to a remote server (I know the URL and IP address).  Do I need to make any
> changes to the remote SQL server?
>
> Thanx,
> --
> Anil Gupte
> www.keeninc.net
> www.icinema.com
>
> "RobinS" <RobinS@NoSpam.yah.none> wrote in message
> news:kNKdnV9vhrb_E_PYnZ2dnUVZ_hmdnZ2d@comcast.com...
> > You should communicate with the database directly, not through
> > ASP pages.
> >
> > Here's an example I have posted before. You can probably find
> > gazillions others by searching these newsgroups from google groups.
> > This one opens the database, reads the Product table, then
> > iterates through it and shows the results.
> >
> > Dim ds As DataSet
> > 'open the connection
> > 'DBConnectionString is in the Project Settings
> > Using cnn As New SqlConnection(My.Settings.DBConnectionString)
> >    cnn.Open()
> >
> >    'define the command
> >    Dim cmd As New SqlCommand
> >    cmd.Connection = cnn
> >    cmd.CommandText = "SELECT * FROM Product"
> >    'define the data adapter and fill the data table
> >    Dim da As New SqlDataAdapter(cmd)
> >    ds = New DataSet
> >    da.Fill(ds, "Product")
> > End Using
> >
> > For Each dr As DataRow In ds.Tables("Product").Rows
> >    Dim ProductID As Integer = CType(dr.Item("ProductID"), Integer)
> >    Dim ProductName As String = dr.Item("ProductName").ToString
> >    Dim ProductNumber As String = dr.Item("ProductNumber").ToString
> >    'Dim Price As Nullable(Of Decimal)
> >    'If .Item("Price") IsNot DBNull.Value Then
> >    '    Price = CType(.Item("Price"), Decimal)
> >    'End If
> >    Dim Description As String = dr.Item("Description").ToString
> >    'Dim ProductType As Integer = CType(.Item("ProductType"), Integer)
> >    'Dim StockType As String = .Item("StockType").ToString
> >    Console.WriteLine(String.Format("ProductID {0}, " & _
> >      "ProductName {1}, {2}ProductNumber {3}, " & _
> >      "Description {4}", ProductID, ProductName, _
> >      ControlChars.CrLf, ProductNumber, Description))
> > Next
> >
> > Robin S.
> > -------------------------------------
> >
> > "Anil Gupte" <anil-l***@icinema.com> wrote in message
> > news:%23utT3IFFHHA.4080@TK2MSFTNGP02.phx.gbl...
> >> Hi All:
> >>
> >> I am looking for general directions on "the right way" to do something,
> >> which is very critical to my application.
> >>
> >> I want to communicate with a SQL server database on a Windows Server (in
> >> the future it could be a Linux MYSQL server, but I don't know for sure).
> >> My application is a desktop application and at various times it may need
> >> to communicate with the server to select, update records etc.
> >>
> >> Now the question is, should I build ASP pages which perform the queries
> >> on the server and have the desktop application read the pages and parse
> >> them? If so how?  Are there any samples (I have done something similar
> >> before in VB 6.0 where I embedded IE in the app and "Screen-scraped").
> >>
> >> Or should I communicate with SQL queries directly with the server?  If so
> >> how?  Again, any tutorials etc online would help.
> >>
> >> Thanx,
> >> --
> >> Anil Gupte
> >> www.keeninc.net
> >> www.icinema.com
> >>
> >>
> >
> >
Author
1 Dec 2006 4:49 PM
Anil Gupte
Thanx, looks like a lot of reading and experimenting ahead. :-)

Show quoteHide quote
"rowe_newsgroups" <rowe_em***@yahoo.com> wrote in message
news:1164905143.913846.238460@n67g2000cwd.googlegroups.com...
> Here's two sites that may help:
>
> Connecting via ADO and ADO.Net with VB.Net and C#
> http://support.sas.com/ctx/samples/index.jsp?sid=817
>
> And for the connection strings:
> http://www.connectionstrings.com/
>
> Thanks,
>
> Seth Rowe
>
>
> Anil Gupte wrote:
>> Thanx, but the critical step that I do not know how to do is to connect
>> to
>> the remote SQL Server, in other words, how do I create a connection
>> string
>> to a remote server (I know the URL and IP address).  Do I need to make
>> any
>> changes to the remote SQL server?
>>
>> Thanx,
>> --
>> Anil Gupte
>> www.keeninc.net
>> www.icinema.com
>>
>> "RobinS" <RobinS@NoSpam.yah.none> wrote in message
>> news:kNKdnV9vhrb_E_PYnZ2dnUVZ_hmdnZ2d@comcast.com...
>> > You should communicate with the database directly, not through
>> > ASP pages.
>> >
>> > Here's an example I have posted before. You can probably find
>> > gazillions others by searching these newsgroups from google groups.
>> > This one opens the database, reads the Product table, then
>> > iterates through it and shows the results.
>> >
>> > Dim ds As DataSet
>> > 'open the connection
>> > 'DBConnectionString is in the Project Settings
>> > Using cnn As New SqlConnection(My.Settings.DBConnectionString)
>> >    cnn.Open()
>> >
>> >    'define the command
>> >    Dim cmd As New SqlCommand
>> >    cmd.Connection = cnn
>> >    cmd.CommandText = "SELECT * FROM Product"
>> >    'define the data adapter and fill the data table
>> >    Dim da As New SqlDataAdapter(cmd)
>> >    ds = New DataSet
>> >    da.Fill(ds, "Product")
>> > End Using
>> >
>> > For Each dr As DataRow In ds.Tables("Product").Rows
>> >    Dim ProductID As Integer = CType(dr.Item("ProductID"), Integer)
>> >    Dim ProductName As String = dr.Item("ProductName").ToString
>> >    Dim ProductNumber As String = dr.Item("ProductNumber").ToString
>> >    'Dim Price As Nullable(Of Decimal)
>> >    'If .Item("Price") IsNot DBNull.Value Then
>> >    '    Price = CType(.Item("Price"), Decimal)
>> >    'End If
>> >    Dim Description As String = dr.Item("Description").ToString
>> >    'Dim ProductType As Integer = CType(.Item("ProductType"), Integer)
>> >    'Dim StockType As String = .Item("StockType").ToString
>> >    Console.WriteLine(String.Format("ProductID {0}, " & _
>> >      "ProductName {1}, {2}ProductNumber {3}, " & _
>> >      "Description {4}", ProductID, ProductName, _
>> >      ControlChars.CrLf, ProductNumber, Description))
>> > Next
>> >
>> > Robin S.
>> > -------------------------------------
>> >
>> > "Anil Gupte" <anil-l***@icinema.com> wrote in message
>> > news:%23utT3IFFHHA.4080@TK2MSFTNGP02.phx.gbl...
>> >> Hi All:
>> >>
>> >> I am looking for general directions on "the right way" to do
>> >> something,
>> >> which is very critical to my application.
>> >>
>> >> I want to communicate with a SQL server database on a Windows Server
>> >> (in
>> >> the future it could be a Linux MYSQL server, but I don't know for
>> >> sure).
>> >> My application is a desktop application and at various times it may
>> >> need
>> >> to communicate with the server to select, update records etc.
>> >>
>> >> Now the question is, should I build ASP pages which perform the
>> >> queries
>> >> on the server and have the desktop application read the pages and
>> >> parse
>> >> them? If so how?  Are there any samples (I have done something similar
>> >> before in VB 6.0 where I embedded IE in the app and "Screen-scraped").
>> >>
>> >> Or should I communicate with SQL queries directly with the server?  If
>> >> so
>> >> how?  Again, any tutorials etc online would help.
>> >>
>> >> Thanx,
>> >> --
>> >> Anil Gupte
>> >> www.keeninc.net
>> >> www.icinema.com
>> >>
>> >>
>> >
>> >
>