473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How can it connect to the database without knowing it's path

Here is an example from the help on the keword OleDbConnection, in VB.Net,
they don't give the path to the database just the word localhost. How can it
connect to the database without knowing where it is. What does the keyword
localhost do.

Thank's

Fia

Public Sub InsertRow(myConnectionString As String)
' If the connection string is null, use a default.
If myConnectionString = "" Then
myConnectionString = "Provider=SQLOLEDB;Data
Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;"
End If
Dim myConnection As New OleDbConnection(myConnectionString)
Dim myInsertQuery As String = "INSERT INTO Customers (CustomerID,
CompanyName) Values('NWIND', 'Northwind Traders')"
Dim myCommand As New OleDbCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Sub
Dec 12 '05 #1
3 1744

"Familjen Karlsson" <fi*****@telia.com> wrote in message
news:C_*********************@newsc.telia.net...
Here is an example from the help on the keword OleDbConnection, in VB.Net,
they don't give the path to the database just the word localhost. How can
it
connect to the database without knowing where it is. What does the keyword
localhost do.

Thank's

Fia

Public Sub InsertRow(myConnectionString As String)
' If the connection string is null, use a default.
If myConnectionString = "" Then
myConnectionString = "Provider=SQLOLEDB;Data
Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;"
End If
Dim myConnection As New OleDbConnection(myConnectionString)
Dim myInsertQuery As String = "INSERT INTO Customers (CustomerID,
CompanyName) Values('NWIND', 'Northwind Traders')"
Dim myCommand As New OleDbCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Sub


Localhost simply refers to the machine you are on at the time (i.e. go to a
DOS prompt and type "ping localhost" you'll get 4 replies.

Looking at the code I am guessing it is connecting to some kind of SQL
Server/MSDE running on the computer so you don't supply a path to the data
file but instead give it the server name and the database name (initial
catalog).
James.
Dec 12 '05 #2
"Familjen Karlsson" <fi*****@telia.com> schrieb
Here is an example from the help on the keword OleDbConnection, in
VB.Net, they don't give the path to the database just the word
localhost. How can it connect to the database without knowing where
it is. What does the keyword localhost do.
Please stay in the thread you've already started.
Thank's

Fia

Public Sub InsertRow(myConnectionString As String)
' If the connection string is null, use a default.
If myConnectionString = "" Then
myConnectionString = "Provider=SQLOLEDB;Data
Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;"
End If
Dim myConnection As New OleDbConnection(myConnectionString)
Dim myInsertQuery As String = "INSERT INTO Customers (CustomerID,
CompanyName) Values('NWIND', 'Northwind Traders')"
Dim myCommand As New OleDbCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Sub

Thanks for the example. As you see, the code uses an SQL server ("SQLOLEDB"
provider). It is not necessary to specify a path because the clients (you)
identify the database by it's name. According to the name, SQL server itself
knows where the database files are stored on the server. You (the client)
does not have to care about.

Your first question was about connecting to an Access database without
specifying a path. This is not possible. To connect to an Access database,
the Jet OleDB-Provider ist used. Access is not a database server, thus you
have to specify the path to the database file.
BTW, database related (language unrelated) question best fit into
microsoft.public.dotnet.framework.adonet
Armin

Dec 12 '05 #3
On Mon, 12 Dec 2005 15:49:54 GMT, "Familjen Karlsson" <fi*****@telia.com> wrote:

¤ Here is an example from the help on the keword OleDbConnection, in VB.Net,
¤ they don't give the path to the database just the word localhost. How can it
¤ connect to the database without knowing where it is. What does the keyword
¤ localhost do.

You can use a DSN and ODBC but that's the wrong direction as far as I am concerned.

Access is a file based, not server based, database system. There is no equivalent to localhost for
Access.
Paul
~~~~
Microsoft MVP (Visual Basic)
Dec 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mohammed AlQuraishi | last post by:
Hi all, I'm trying to connect to an MS Access database using ADO.NET and C#, but I'm getting the dreaded "Microsoft Jet database engine cannot open the file 'x'. It is already opened exclusively...
0
by: Bernard Dhooghe | last post by:
Environment: DB2 UDB LUW (AIX) 8.2 Database instance: test migration to 64 bit Clients: 32 bit, embedded sql, db2 clp When PATH/LIBPATH point to the 32 lib environment (/usr/opt/db2_08_01/bin...
3
by: Dave F. | last post by:
I am using ODBC to connect to dBase data on a remote server. The ASP.NET app will be running on Win 2k or 2003 server. I have tried to make it work but all I can get is an error. ...
4
by: Frank | last post by:
Hi I am a poor student studying towards my MCSD. I have managed to get a cheapish student version of vb.net. Problem is that this version does not connect to sql databases and I need it to...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
5
by: news.telia.net | last post by:
Hi! I have a question. I have installed php and mysql on an apache-server on windows and I can't connect to the server. I tried to create a database (since I am trying to learn howto). My...
11
by: Mikael Arhelger | last post by:
Hello, This has been posted a few times but still I could not find a way to connect to our database. We run DB2 Express on WIN2K server with XP clients. I can ping inside network and to the...
3
by: Michael | last post by:
Hi. I am looking for way to connect to database that is in another subdomain of same hosting machine. The location of file DB here: http://name1.syte.com I am here: http://name2.syte.com The...
5
by: db2admin | last post by:
hello, I am wondering if i can install db2 connect product on a AIX server which already has db2 ese installed on it ? regards,
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.