PC Review


Reply
Thread Tools Rate Thread

Any sample to connect a remoted database through Excel?

 
 
Eric
Guest
Posts: n/a
 
      9th May 2008
Does anyone have any sample to connect a remoted database through Excel?
I need to make a connection with a database in China, and I locate in HK.
Could anyone give me any suggestions on what I need to retrieve any data from
a database?
What I can think of is
URL, username, password, ...
Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric

 
Reply With Quote
 
 
 
 
FerGo
Guest
Posts: n/a
 
      9th May 2008
You can try through an ODBC connection, depending of what DB you try to
connect. After that you only need to configure the connection in the DATA -
CONNECTIONS tab in Office Excel 2007.

Regards.

"Eric" <(E-Mail Removed)> escribió en el mensaje de
noticias96FB62A-57A0-4717-81A4-(E-Mail Removed)...
> Does anyone have any sample to connect a remoted database through Excel?
> I need to make a connection with a database in China, and I locate in HK.
> Could anyone give me any suggestions on what I need to retrieve any data
> from
> a database?
> What I can think of is
> URL, username, password, ...
> Does anyone have any suggestions?
> Thanks in advance for any suggestions
> Eric
>

 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      9th May 2008
Assuming you have the ODBC drivers and a stable connection to the database
server then you should be able to use MS Query which you access via Data ->
Import External Data -> new Database Query.

That will allow you to read from the database. If you need to write back
then you will need to use VBA code with ADODB Recordsets.
--
HTH...

Jim Thomlinson


"Eric" wrote:

> Does anyone have any sample to connect a remoted database through Excel?
> I need to make a connection with a database in China, and I locate in HK.
> Could anyone give me any suggestions on what I need to retrieve any data from
> a database?
> What I can think of is
> URL, username, password, ...
> Does anyone have any suggestions?
> Thanks in advance for any suggestions
> Eric
>

 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      9th May 2008
Thank everyone very much for any suggestions
Does anyone have any sample for download? therefore, I can see the approach.
I would like to do some coding.
Thank everyone very much for your quick response
Eric

"Jim Thomlinson" wrote:

> Assuming you have the ODBC drivers and a stable connection to the database
> server then you should be able to use MS Query which you access via Data ->
> Import External Data -> new Database Query.
>
> That will allow you to read from the database. If you need to write back
> then you will need to use VBA code with ADODB Recordsets.
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Eric" wrote:
>
> > Does anyone have any sample to connect a remoted database through Excel?
> > I need to make a connection with a database in China, and I locate in HK.
> > Could anyone give me any suggestions on what I need to retrieve any data from
> > a database?
> > What I can think of is
> > URL, username, password, ...
> > Does anyone have any suggestions?
> > Thanks in advance for any suggestions
> > Eric
> >

 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      10th May 2008
Not sure either ODBC or OLE work over http (since you mention a URL...)

Also - more details: what type of database, where hosted, VPN , etc ?

Tim


"Eric" <(E-Mail Removed)> wrote in message
news96FB62A-57A0-4717-81A4-(E-Mail Removed)...
> Does anyone have any sample to connect a remoted database through Excel?
> I need to make a connection with a database in China, and I locate in HK.
> Could anyone give me any suggestions on what I need to retrieve any data
> from
> a database?
> What I can think of is
> URL, username, password, ...
> Does anyone have any suggestions?
> Thanks in advance for any suggestions
> Eric
>



 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      10th May 2008
Thank everyone very much for suggestions
Do you mean that I cannot connect ODBC through http?
As I remember that IP address, web site, username, password are given in
order to make any connection.
Could you please give me more describtion?
Thank you very much for your suggestion
Eric

"Tim Williams" wrote:

> Not sure either ODBC or OLE work over http (since you mention a URL...)
>
> Also - more details: what type of database, where hosted, VPN , etc ?
>
> Tim
>
>
> "Eric" <(E-Mail Removed)> wrote in message
> news96FB62A-57A0-4717-81A4-(E-Mail Removed)...
> > Does anyone have any sample to connect a remoted database through Excel?
> > I need to make a connection with a database in China, and I locate in HK.
> > Could anyone give me any suggestions on what I need to retrieve any data
> > from
> > a database?
> > What I can think of is
> > URL, username, password, ...
> > Does anyone have any suggestions?
> > Thanks in advance for any suggestions
> > Eric
> >

>
>
>

 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      10th May 2008
You need to provide more details on *your exact requirements*.
General questions like this are difficult to address.

Tim

"Eric" <(E-Mail Removed)> wrote in message
news:89FDD2B4-AA9B-49F0-AC33-(E-Mail Removed)...
> Thank everyone very much for suggestions
> Do you mean that I cannot connect ODBC through http?
> As I remember that IP address, web site, username, password are given in
> order to make any connection.
> Could you please give me more describtion?
> Thank you very much for your suggestion
> Eric
>
> "Tim Williams" wrote:
>
>> Not sure either ODBC or OLE work over http (since you mention a URL...)
>>
>> Also - more details: what type of database, where hosted, VPN , etc ?
>>
>> Tim
>>
>>
>> "Eric" <(E-Mail Removed)> wrote in message
>> news96FB62A-57A0-4717-81A4-(E-Mail Removed)...
>> > Does anyone have any sample to connect a remoted database through
>> > Excel?
>> > I need to make a connection with a database in China, and I locate in
>> > HK.
>> > Could anyone give me any suggestions on what I need to retrieve any
>> > data
>> > from
>> > a database?
>> > What I can think of is
>> > URL, username, password, ...
>> > Does anyone have any suggestions?
>> > Thanks in advance for any suggestions
>> > Eric
>> >

>>
>>
>>



 
Reply With Quote
 
Eric
Guest
Posts: n/a
 
      11th May 2008
Thank everyone very much for suggestions

Once I connect a data base through following code,
Could you please give me one example on retrieving data?
I would like to retrieve the variable "name" and "phone" under the table
"member", and insert into column A for name and column B for phone.
Could you please give me any suggestions?
Thank you very much for your suggestions
Eric


Dim adoCon As Object
Dim rsCommon As Object

Sub Variable()
strSQLServerName = "IP_address"
strSQLDBUserName = "Your_SQL_UserName"
strSQLDBPassword = "Your_SQL_Password"
strSQLDBName = "YOur_SQL_DBName"

strCon = "Server=" & strSQLServerName & ";User ID=" & strSQLDBUserName &
";Password=" & strSQLDBPassword & ";Database=" & strSQLDBName & ";"

Call openDatabase(strCon)

End Sub

Sub openDatabase(strCon)

strCon = "Provider=SQLOLEDB;Connection Timeout=90;" & strCon
Set adoCon = CreateObject("ADODB.Connection")

On Error Resume Next
adoCon.connectionstring = strCon
adoCon.Open

If Err.Number <> 0 Then MsgBox Err.Description, vbCritical
On Error GoTo 0

'Your recordset, so look for the fields you want using this rs object
Set rsCommon = CreateObject("ADODB.Recordset")

'do your thing with the rs here
Set rsCommon = Nothing

End Sub

Sub closeDatabase()
If adoCon Is Not Nothing Then
adoCon.Close
Set adoCon = Nothing
End If
End Sub



"Tim Williams" wrote:

> You need to provide more details on *your exact requirements*.
> General questions like this are difficult to address.
>
> Tim
>
> "Eric" <(E-Mail Removed)> wrote in message
> news:89FDD2B4-AA9B-49F0-AC33-(E-Mail Removed)...
> > Thank everyone very much for suggestions
> > Do you mean that I cannot connect ODBC through http?
> > As I remember that IP address, web site, username, password are given in
> > order to make any connection.
> > Could you please give me more describtion?
> > Thank you very much for your suggestion
> > Eric
> >
> > "Tim Williams" wrote:
> >
> >> Not sure either ODBC or OLE work over http (since you mention a URL...)
> >>
> >> Also - more details: what type of database, where hosted, VPN , etc ?
> >>
> >> Tim
> >>
> >>
> >> "Eric" <(E-Mail Removed)> wrote in message
> >> news96FB62A-57A0-4717-81A4-(E-Mail Removed)...
> >> > Does anyone have any sample to connect a remoted database through
> >> > Excel?
> >> > I need to make a connection with a database in China, and I locate in
> >> > HK.
> >> > Could anyone give me any suggestions on what I need to retrieve any
> >> > data
> >> > from
> >> > a database?
> >> > What I can think of is
> >> > URL, username, password, ...
> >> > Does anyone have any suggestions?
> >> > Thanks in advance for any suggestions
> >> > Eric
> >> >
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      11th May 2008
See below

Tim


"Eric" <(E-Mail Removed)> wrote in message
news:E0A15D8D-5343-45A1-8510-(E-Mail Removed)...
> Thank everyone very much for suggestions
>
> Once I connect a data base through following code,
> Could you please give me one example on retrieving data?
> I would like to retrieve the variable "name" and "phone" under the table
> "member", and insert into column A for name and column B for phone.
> Could you please give me any suggestions?
> Thank you very much for your suggestions
> Eric
>
>
> Dim adoCon As Object
> Dim rsCommon As Object
>
> Sub Variable()
> strSQLServerName = "IP_address"
> strSQLDBUserName = "Your_SQL_UserName"
> strSQLDBPassword = "Your_SQL_Password"
> strSQLDBName = "YOur_SQL_DBName"
>
> strCon = "Server=" & strSQLServerName & ";User ID=" & strSQLDBUserName &
> ";Password=" & strSQLDBPassword & ";Database=" & strSQLDBName & ";"
>
> Call openDatabase(strCon)
>
> End Sub
>
> Sub openDatabase(strCon)
>
> strCon = "Provider=SQLOLEDB;Connection Timeout=90;" & strCon
> Set adoCon = CreateObject("ADODB.Connection")
>
> On Error Resume Next
> adoCon.connectionstring = strCon
> adoCon.Open
>
> If Err.Number <> 0 Then MsgBox Err.Description, vbCritical
> On Error GoTo 0
>
> 'Your recordset, so look for the fields you want using this rs object
> Set rsCommon = CreateObject("ADODB.Recordset")
>


dim i, shtData
i=2
set shtData = this workbook.sheets("Members")
rsCommon.Open "select t.name, t.phone from member t", adoCon
if not rsCommon.EOF then
do while not rsCommon.EOF
shtData.cells(i,1).value=rsCommon.Fields("name").value
shtData.cells(i,2).value=rsCommon.Fields("phone").value
i=i+1
rsCommon.movenext
loop
end if


> Set rsCommon = Nothing
>
> End Sub
>
> Sub closeDatabase()
> If adoCon Is Not Nothing Then
> adoCon.Close
> Set adoCon = Nothing
> End If
> End Sub
>
>
>
> "Tim Williams" wrote:
>
>> You need to provide more details on *your exact requirements*.
>> General questions like this are difficult to address.
>>
>> Tim
>>
>> "Eric" <(E-Mail Removed)> wrote in message
>> news:89FDD2B4-AA9B-49F0-AC33-(E-Mail Removed)...
>> > Thank everyone very much for suggestions
>> > Do you mean that I cannot connect ODBC through http?
>> > As I remember that IP address, web site, username, password are given
>> > in
>> > order to make any connection.
>> > Could you please give me more describtion?
>> > Thank you very much for your suggestion
>> > Eric
>> >
>> > "Tim Williams" wrote:
>> >
>> >> Not sure either ODBC or OLE work over http (since you mention a
>> >> URL...)
>> >>
>> >> Also - more details: what type of database, where hosted, VPN , etc ?
>> >>
>> >> Tim
>> >>
>> >>
>> >> "Eric" <(E-Mail Removed)> wrote in message
>> >> news96FB62A-57A0-4717-81A4-(E-Mail Removed)...
>> >> > Does anyone have any sample to connect a remoted database through
>> >> > Excel?
>> >> > I need to make a connection with a database in China, and I locate
>> >> > in
>> >> > HK.
>> >> > Could anyone give me any suggestions on what I need to retrieve any
>> >> > data
>> >> > from
>> >> > a database?
>> >> > What I can think of is
>> >> > URL, username, password, ...
>> >> > Does anyone have any suggestions?
>> >> > Thanks in advance for any suggestions
>> >> > Eric
>> >> >
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to connect to database through Macro Excel in MAC jibanendu General Software 0 22nd Apr 2011 07:23 AM
Any macro programming sample for accessing database through Excel? Eric Microsoft Excel Programming 7 11th May 2008 01:50 AM
Any sample to connect a remoted database through Excel Eric Microsoft Excel Misc 0 9th May 2008 05:08 PM
Need sample code to connect Excel to Mercury Quality Center Michael Microsoft Excel Programming 2 28th Mar 2007 01:01 AM
connect a form to excel database =?Utf-8?B?S2F0aHk=?= Microsoft Excel Misc 5 10th Oct 2005 06:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:50 AM.