Connecting Classic ASP to SQL Server 2012 - vbscript

I have 2 servers, a win2000+ Classic ASP application server, the other is Server 2012 with a SQL 2012 instance.
On the application server I can create an ODBC DSN (name is "test") to connect to the SQL instance, and access database (mdb). I use "test" to link tables in B, so the connection is fine. But on my ASP page I cannot connect to the SQL instance, and an error message is displayed: "SQL Server does not exist or access denied".
Here's my code:
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DSN=test;UID=user;PWD=pwd;DATABASE=test"
conn.close
set conn = nothing
response.write "ok"

Try this?
Dim MM_MyServer_STRING
MM_MyServer_STRING = "SERVER=test;DATABASE=test;user id=user;password=pwd"
Set ConnectMe = Server.CreateObject("ADODB.Recordset")
ConnectMe.ActiveConnection = MM_MyServer_STRING

Related

Connection string to connect to oracle 11g from classic asp

I set up an ODBC connection using ODBC Data Source Administrator . I have named it "BIOTPL" connect like this:
The corresponding code is :
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "Provider=OraOLEDB.Oracle;Data Source=simple_dsn;User Id=USER;Password=PASSWORD;"
But I am getting this error .
ORA-12154: TNS:could not resolve the connect identifier specified
How can I solve this error ? Please help me .
The following code works for me .
Set Conn = Server.Createobject("ADODB.Connection")
Conn.open "Driver={Oracle in OraDb11g_home1};Server=10.11.201.170; Uid=USER;Pwd=PASSWORD;"
This is how I connect to Oracle using VBscript.
ConnectionString = "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" + DBCONN + ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" + DatabaseSID + " ))); uid=" + DatabaseUser + ";pwd=" + DatabasePassword + ";"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open ConnectionString
I had a similar error when using classic ASP and Conn.Open "Provider=OraOLEDB.Oracle..." as is shown in the code above.
However, if I used Conn.Open "DSN=MyDSN;User ID=..." the connection worked.
In order to use the "Provider=OraOLEDB.Oracle..." syntax, I had to create a 32-bit application pool in IIS - create the application pool, then set Enable 32-Bit Applications = True (in advanced settings).
Note that 64-bit Windows has both 32 and 64-bit ODBC configurations. The default ODBC manager is 64-bit. Classic ASP applications can run in 64-bit mode and use 64-bit ODBC DSNs with some limitations like using Conn.Open "DSN=MyDSN;User ID=...".
If you use the Conn.Open "DSN=MyDSN..." syntax and you run in 32-bit mode, you will need to configure the DSN using the 32-bit ODBC manager. To access the 32-bit ODBC manager, run C:\Windows\SysWOW64\odbcad32.exe
The 32-bit and 64-bit ODBC manager windows look identical - there will just be different lists of DSNs that are configured.
One other tool that I found helpful is to create a file named DBConnection.udl. (The file name is not important - just the .udl suffix.) When you double-click the file, a Data Link Properties window will open and allow you to select the provider and connection info. There is also a test button to verify your connection. After setting the connection variables, close the window and open the DBConnection.udl file with a text editor (notepad.exe works) and it will display the OLEDB init string that can be used in your application.

Fatal two-task communication protocol error in oracle 10 g

I'm using QTP 10.
Trying to connect to Oracle DB via oracle client 10.2(windows xp).
I had prev oracle 9i & i've upgraded it to 10.2 thought it would resolve.
But still i'm getting "fatal two-task communication protocol error".
Is there any solution for that .
i see the same client version is working with windows 7 & oracle 10.2.
Appreciate your help..
I am using ADODB to connect to Oracle 10 and 11 from QTP (from VBScript in generall).
The code to connect is:
Set connection = createobject("adodb.connection")
connection.open "Driver={Microsoft ODBC for Oracle};" + _
"Server=host:1521/database_sid;Uid=username;Pwd=password;"
where:
host - is a server name where Oracle is running
1521 - is a port number (1521 is default port, but could be different on your system)
database_sid - is a SID of the database
You need to ask your database administrator for these values.
This code requires Oracle Instant Client.
You need to download proper package for your system (Win 32, Win 64 etc.) from here: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
Unpack it to any directory and place this directory in a PATH environment variable.
and then, the code to execute queries and get results looks like this:
Set rs = createobject("adodb.recordset")
rs.open "SELECT fieldname FROM table WHERE etc.", connection
while not rs.eof
value = rs.fields( "fieldname" )
.....
loop

Error connecting to Oracle with Classic ASP on IIS7

I just replaced the hard drive on my Windows 7 machine (my development computer). I did not have any issues with this working on the old hard drive, but I think I remember I had to change something or install something, but I do not remember.
The following code works perfectly on my live machine (Windows 2003 with IIS6).
OracleConn = "Provider=MSDASQL.1;Persist Security Info=True;User ID=TheUID;Password=ThePW;DSN=TheDB;DBQ=ORA_PRD1;"
SqlStr = "SELECT * FROM TestTable WHERE Somefield = 'Something'"
Set Objrs = Server.CreateObject("ADODB.RecordSet")
Objrs.Open SqlStr, OracleConn, adOpenStatic, adLockOptimistic,adCmdText
While Not Objrs.EOF
Response.Write "Some Stuff and whatever <br>"
Objrs.MoveNext
Wend
Objrs.Close
Set Objrs = Nothing
When I run it, I am getting the following error:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
I did create a .udl file to get the connection string and to test the database connection and it works fine. I also have an app on my computer that uses the same ODBC drivers to connect to the same database and it works fine.
I dont have any issues connecting to an Access database at all. Connecting to Oracle seems to be the only issue I am having.

Problem of attaching a database to visual studio 2010

I press add connection in database explorer then put the server name which is Rabbitmasterpc
windows Authentication, attach a database file: --> I browse to the database i attached.. give it a logical name..click 'ok'. And what I get:
"A network-related or instance specific error occured while
establishing a connection to SQL Server. The server was not found or
was not accessable. Verify that the instance name is correct and that
SQL Server is configured to allow removte connections. (provider:
Named Pipes Provider, error:40- Could not open a connection to SQL
server)"
UPDATE:
http://www.mssqltips.com/tip.asp?tip=1673
The article says it is in facets..but i dont have it inside
Check if SQL Server is configured (via SQL Server Configuration Manager) to accept remote connections.
Also, you may need to check the Connections property page for your database in Management Studio, as well as firewall settings:
http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx
Try using code below to open the connection.
Try
Dim objconnection As SqlConnection = New _
SqlConnection("Server=localhost;Database=DATABASENAME;" & _
"user ID = YOURUSERID; password = YOURPASSWORD;")
objconnection.Open()
objconnection.Close()
MessageBox.Show("Database Connection Success")
Catch ex As Exception
MessageBox.Show("Database Connection Error: " & ex.Message)
End Try

Not able to connect from excel(2003) to oracle server

I am trying to connect to oracle server from excel...i dont want to install oracle client in my system(presently there is no oracle client) So i am using Microsoft ODBC for Oracle
Dim strConnection, conn, rs, strSQL
strConnection = "Driver={Microsoft ODBC for Oracle};Server=ServerName;Uid=username;Pwd=password;"
Set conn = CreateObject("ADODB.Connection")
conn.Open strConnection
'insq = "insert into State (States) values ('" + Sheet1.Cells(1, 5) + "')"
'conn.Execute insq
conn.Close
Set conn = Nothing
The Error is : Oracle Client and networking component not found
I have also tried using connection string
trConnection = "Provider=OraOLEDB.Oracle;Data Source=Datasource;User Id=username;Password=password;"
'strConnection = "Provider=MSDAORA;Data Source==Datasource;User Id=username;Password=password;"
But still i am getting an error
My main question is can we connect from excel to oracle server without oracle client
in my system..
Ultimately you need something on your system that 'speaks Oracle'. To begin with it needs to know how the protocol works to get the specified password accepted by Oracle, even before it gets into doing anything with data.
You are best off installing the Instant Client (Basic and ODBC supplement).

Resources