473,404 Members | 2,179 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,404 software developers and data experts.

Visual Basic Tip Of The Week #1

8,435 Expert 8TB
Originally posted by sashi...

Connection string More samples

MsAccess - Connection String

Standard security
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  2.            "Data Source=c:\somepath\myDb.mdb;"
If using a Workgroup (System Database)
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  2.            "Data Source=c:\somepath\mydb.mdb;" & _ 
  3.            "Jet OLEDB:System Database=MySystem.mdw", _
  4.            "myUsername", "myPassword"
If MDB has a database password
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  2.            "Data Source=c:\somepath\mydb.mdb;" & _ 
  3.            "Jet OLEDB:Database Password=MyDbPassword", _
  4.            "myUsername", "myPassword"
If want to open up the MDB exclusively
Expand|Select|Wrap|Line Numbers
  1. oConn.Mode = adModeShareExclusive
  2. oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  3.            "Data Source=c:\somepath\myDb.mdb;"
If MDB is located on a network share
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  2.            "Data Source=\\myServer\myShare\myPath\myDb.mdb"
ODBC - Open Database Connectivity

DSN
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "DSN=mySystemDSN;" & _ 
  2.            "Uid=myUsername;" & _ 
  3.            "Pwd=myPassword"
File DSN
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "FILEDSN=c:\somepath\mydb.dsn;" & _ 
  2.            "Uid=myUsername;" & _
  3.            "Pwd=myPassword"
MsSQL Server - Connection String

For Standard Security
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "Provider=sqloledb;" & _ 
  2.            "Data Source=myServerName;" & _
  3.            "Initial Catalog=myDatabaseName;" & _
  4.            "User Id=myUsername;" & _
  5.            "Password=myPassword"
OR

Expand|Select|Wrap|Line Numbers
  1. oConn.Open "Provider=sqloledb;" & _ 
  2.            "Server=myServerName;" & _
  3.            "Database=myDatabaseName;" & _
  4.            "User Id=myUsername;" & _
  5.            "Password=myPassword"
For a Trusted Connection
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "Provider=sqloledb;" & _
  2.            "Data Source=myServerName;" & _
  3.            "Initial Catalog=myDatabaseName;" & _
  4.            "Integrated Security=SSPI"
To connect to a "Named Instance"
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "Provider=sqloledb;" & _
  2.            "Data Source=myServerName\myInstanceName;" & _
  3.            "Initial Catalog=myDatabaseName;" & _
  4.            "User Id=myUsername;" & _
  5.            "Password=myPassword"
Note: In order to connect to a SQL Server 2000 "named instance", you must have MDAC 2.6 (or greater) installed.

To Prompt user for username and password
Expand|Select|Wrap|Line Numbers
  1. oConn.Provider = "sqloledb"
  2. oConn.Properties("Prompt") = adPromptAlways
  3. oConn.Open "Data Source=myServerName;" & _
  4.            "Initial Catalog=myDatabaseName"
To connect to SQL Server running on the same computer
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "Provider=sqloledb;" & _
  2.            "Data Source=(local);" & _
  3.            "Initial Catalog=myDatabaseName;" & _
  4.            "User ID=myUsername;" & _
  5.            "Password=myPassword"
To connect to SQL Server running on a remote computer (via an IP address)
Expand|Select|Wrap|Line Numbers
  1. oConn.Open "Provider=sqloledb;" & _
  2.            "Network Library=DBMSSOCN;" & _
  3.            "Data Source=xxx.xxx.xxx.xxx,1433;" & _
  4.            "Initial Catalog=myDatabaseName;" & _
  5.            "User ID=myUsername;" & _
  6.            "Password=myPassword"
Apr 8 '07 #1
0 1528

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

Similar topics

33
by: John Timbers | last post by:
I'd like to purchase Visual C# .Net for learning purposes only since it's a lot cheaper than Visual Studio (note that I'm a very experienced C++ developer). Can someone simply clarify the basic...
6
by: Tina | last post by:
Hello, I'm currently preparing for the exam 70-315. I'm using the Self-paced training kit "Developing Web Applications with Microsoft Visual C#.NET", but I find it rather difficult. I have...
3
by: Frank van der Kleij | last post by:
I want to make een marco in visual Basic that: can look at a range and can check, in every cel in that range, if it is equal as 1 en than change the text color to yellow. I am searching for a...
3
by: Jay Patel | last post by:
Hello, I need to write visual basic.net code to interface with a Mettler Toledo Shipping Scale that interfaces with a PC via USB or a serial port. I have seen example code on how to communicate...
16
by: Jesse Liberty | last post by:
I am writing a new book on Visual Basic 2005, targeted at VB6 programmers, and to some degree VB.NET 1.x programmers. I'd like to sign up a (limited) number of volunteers to read the book and...
2
by: frossberg | last post by:
Hello! I tried to install the Visual Basic.NET Resource Kit (http://msdn.microsoft.com/vbasic/vbrkit/) but obviously something went very wrong and now it sems impossible both to repair and to...
3
by: Crazy Cat | last post by:
Hi, I'm developing an application that is basically a VB.NET front end to a SQL Server Express 2005 database -- right now I'm using VB.NET 2005 Express until my MSDN subscription gets delivered...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
4
by: corky20 | last post by:
Can someone help...i've only started learning visual basic and i'm pretty new to programming(i know but everyones been there at one point) and need help with a question! A man is paid at the...
8
by: Chris Asaipillai | last post by:
Hi there I have some questions for those experienced Visual Basic 6 programmers out there who have made the transition from VB6 to Vb.net. How long did it take you to learn at least the basic...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.