473,387 Members | 1,464 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,387 software developers and data experts.

OLEDB Connection String

I have a OLEDB Connection String that is working very well for me. My
question is that I read that you can store the Connection String in a
seperate include file or somewhere else. I am just wondering where is
the proper place to store this Connection String and how do I call it
from my application.
My Example is below

Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.RecordSet")
Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
Catalog = TestSQL; User Id = sa; Password = test"
sSQL = "SELECT * FROM Html ORDER BY HtmlName ASC"
Set Rs = Conn.Execute(sSQL)
Do While NOT Rs.EOF
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing

Would the answer be to put
Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
Catalog = TestSQL; User Id = sa; Password = test"
into an asp page and then use <!--#include file="test.asp"-->
like

Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.RecordSet")
<!--#include file="test.asp"-->
sSQL = "SELECT * FROM Html ORDER BY HtmlName ASC"
Set Rs = Conn.Execute(sSQL)
Do While NOT Rs.EOF
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing

Dec 16 '05 #1
2 8745
MasterChief wrote:
I have a OLEDB Connection String that is working very well for me. My
question is that I read that you can store the Connection String in a
seperate include file or somewhere else. I am just wondering where is
the proper place to store this Connection String and how do I call it
from my application.
My Example is below
<snip of irelevant code> Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
Catalog = TestSQL; User Id = sa; Password = test"
I hope you are not really using the sa account for your application code ...
and that the password is not really "test".

<snip of irelevant code>
Would the answer be to put
Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
Catalog = TestSQL; User Id = sa; Password = test"
into an asp page and then use <!--#include file="test.asp"-->


That's one way. I ususally create a function in the include file that
returns the connection string:

<%
function GetConnectString()
GetConnectString="<your connection string>"
end function
%>

Then
<!--#include file="test.asp"-->
<%
dim sConnect
sConnect=GetConnectString
....
Conn.Open sConnect
%>

Using a function allows you to add arguments to control which connection
string to return if you have multiple strings that could be used (perhaps a
test vs production environment). You could also use the server_name
servervariable to control which connection string gets returned.

Equally valid is using an application variable to store the string,
initializing it in the application_onstart event in global.asa.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Dec 16 '05 #2
Yes you are correct about the password and such. I just wanted to throw
up an example really fast. Thank you for your help.
I hope you are not really using the sa account for your application code ...
and that the password is not really "test".

<snip of irelevant code>

Would the answer be to put
Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
Catalog = TestSQL; User Id = sa; Password = test"
into an asp page and then use <!--#include file="test.asp"-->


That's one way. I ususally create a function in the include file that
returns the connection string:

<%
function GetConnectString()
GetConnectString="<your connection string>"
end function
%>

Then
<!--#include file="test.asp"-->
<%
dim sConnect
sConnect=GetConnectString
...
Conn.Open sConnect
%>

Using a function allows you to add arguments to control which connection
string to return if you have multiple strings that could be used (perhaps a
test vs production environment). You could also use the server_name
servervariable to control which connection string gets returned.

Equally valid is using an application variable to store the string,
initializing it in the application_onstart event in global.asa.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Dec 16 '05 #3

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

Similar topics

7
by: aacool | last post by:
Hi, I've been trying to open an Excel connection through OLEDB with the code below: string ConnectString =@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + fileName.Text +...
1
by: Mark Ogilvie | last post by:
Hi I'm new to C#, and have a problem which I'm sure is simple. I have the following 3 lines of code: string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data...
9
by: Pam Ammond | last post by:
I need the code to update the database when Save is clicked and a text field has changed. This should be very easy since I used Microsoft's wizards for the OleDBAdapter and OleDBConnection, and...
2
by: Martin | last post by:
Hi, I currently have an application that connects to an MS ACCESS database. This application uses an OLEDB connection string for MS ACCESS. Now, I'd like to upsize the application so I converted...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
5
by: petro | last post by:
Hello all, My asp.net web application works on my machine but I get the following error on our test web server, There is only one oracle home on the test server. Does anyone know how to resolve...
3
by: blue875 | last post by:
When I run this connection, I get a security error. String connectStr = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"User Id=USER; Password=PASS;" + @"Data Source=\\SERVER\DIRECTORY\Data.mdb;" +...
5
by: Jesse Albert | last post by:
Hiyo, I'm trying to import a CSV file into a datatable using either ODBC or OLEDB. One of the columns contains an IP Address. For some reason, the IP address will not display correctly. All of...
6
by: =?Utf-8?B?S3VuIE5pdQ==?= | last post by:
Dear all, I'm trying to use oledb to get the content of an excel file. Now I can use oledb to get the content of a datasheet. But I should know the name of the datasheet in advance. How can I...
1
by: ErikJL | last post by:
I have a simple webservice that performs a SELECT query against a database, and then an INSERT statement on the same database/table. The problem arises at the time when we create the second OleDB...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.