Sql Express Connection in ASP - asp-classic

I am trying to connect to sql express db and inserting record to one of the table inside it using following code.
set conn=Server.CreateObject("ADODB.Connection")
SQL_Conn_STRING = "Driver={SQL Server};Server=(local);Database=classic_asp_poc;uid=my-domain\username;pwd=my password"
conn.Open SQL_Conn_STRING
Response.Write("con open")
I am getting error on open connection. Is there any problem in my connection string?

If you're using mssql express, you need to add \SQLEXPRESS to your database address/ip, so in your example you would use Server=(local\SQLEXPRESS)
You're using an odbc connection string. OLEDB or native client strings are the preferred method eg
SQL_Conn_STRING = "Provider=sqloledb;Data Source=local\SQLEXPRESS;Initial Catalog=classic_asp_poc;User Id=my-domain\username;Password=my password"
See this easy to remember link for more examples
http://www.connectionstrings.com/sql-server/

Related

How I connect with Oracle Database in asp.net

I want to connect with oracle instead of Microsoft access database.Please help me.This is the code for asp.net.It works fine.
set Con=Server.createobject("ADODB.Connection")
set Rs=Server.createobject("ADODB.Recordset")
Con.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\test.mdb"
You can use oracle client just like Sql client

ASP.NET connection string for SQL Server 2012

I am having some trouble with a connection string between an ASP app sat on IIS and an existing SQL Server 2012 instance.
The current connection string that works is as follows:
Data Source=SERVER1;Initial Catalog=CORE;User
ID=testuser;Password=password;
MultipleActiveResultSets=true;Connection Timeout=200;pooling=false
The ODBC driver installed is SQL Server V 6.01.7601.17514. I then added the latest driver SQL Server Native Client 11 and tried adjusting the connection string in IIS with no luck.
I tried both ODBC and OLE DB strings from connectionstrings.com.
OLEDB
Provider=SQLNCLI11;Server=SERVER1;Database=CORE;Uid=testuser;Pwd=password;
ODBC
Driver={SQL Server Native Client 11.0};Server=SERVER1;Database=CORE;Uid=testuser;Pwd=password;
Each time I get a login prompt which I don't understand why the connection string is failing to supply these details with? What am I missing here?
Just having a look though some of the similar questions, some mentions named pipes which is enabled...
The first connection string is valid for the Net Framework Data Provider (the SqlClient classes), while the others are for the OleDb provider or ODBC provider.
Of course you should use the connection string that your provider understand.
If, in your code, you use the SqlClient classes (SqlConnection, SqlCommand) then you need to use the first connection string, if you use OleDbConnection or ODBCConnection you should use the others
See connectionstrings.com
I've always done it this way:
Data Source=;Initial Catalog=;UID=;PWD=;
I also recommend you put the connection string in a config file for easy editing like this: http://www.connectionstrings.com/Articles/Show/store-connection-string-in-web-config

Cannot open database 'dbname' requested by the login. The login failed

Firstly, I know that there are a lot of similar topics, but none seem to solve my problem.
I have inherited a project where the front-end is built in ASP.NET and the CMS is built in classic ASP. I'm in the process of setting up a local development environment where I've copied the database from the live server and am configuring the website to connect to my new local DB.
The ASP.NET part is connecting with the connection string Data Source=.\\SQLEXPRESS; Database=DBNAME; Trusted_Connection=True; but I had to mess about with Application Pools and Permissions.
I'm having a problem with getting the classic ASP part of the website to connect to the SQL database. The error I am recieving is:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "DBNAME" requested by the login. The login failed.
/cms/connections/Conn.asp, line 18
The code in that file is:
12. Dim Conn_STRING, URL, mailHost
13. Conn_STRING = "Driver={SQL Server}; Server=.\SQLEXPRESS; Database=DBNAME; Trusted_Connection=True;"
15. Dim conn
16. set conn = Server.CreateObject("ADODB.Connection")
17. conn.ConnectionString = Conn_STRING
18. conn.Open
I know it's a permission problem or some sort, but I can't get to the bottom of it. I'll appreciate any help at all :)
hmmmm, well, the asp.net part is using SQLExpress, connected via an attached file. DBNAME in the first example is going to refer to a db file name in the actual asp.net project. It's been quite a long time since I last used classic ASP, but I'd be STUNNED if it supports this. You need to attach the db file to an actual sql server and use it that way.
server=mycomputername\sqlexpress; database=DBNAME; user id=username; password=password
You'll need to open your database in sql express mngmt studio
http://www.microsoft.com/download/en/details.aspx?id=7593
Go into your security settings for that user and set the default database to "dbname" (whatver your real dbname is of course)
Ensure your app pool is set to run under the user that has permissions to that database. It may just be easier to enable mixed mode authentication and create a sql user to connect to the database rather than messing around with windows authentication on an app pool.
You wil lof course need to change your connection string then to support the sql authentication if you go that route.
http://msdn.microsoft.com/en-us/library/ms143705%28v=sql.90%29.aspx

What connection string do I use for Classic ASP and Oracle 10g?

I have Oracle 10g and have installed ODBC via the instant client. I am able to use the ODBC administrator and set up a DSN and test successfully, and whenever I use Microsoft Access I can connect to my database no problem. I can also use Visual Web Developer to traverse the data.
But, when I try and use Classic ASP with:
myConn.Open "DSN=oracle10g;" & _
"Uid=myOracleUsername;" & "Pwd=myOraclePassword"
I get:
-2147467259Specified driver could not be loaded due to system error 5 (Oracle in instantclient10_2).
An error occurred while trying to create Server Object.
I have searched various places but nothing seems to work. All ORACLE_HOME, TNSnames, IUSR_X security, all is correct. I am thinking it is a DSN connection string problem.
Anyone know?
Try using the following DSN-less connection string:
myConn.Open "Provider=MSDAORA;Data Source=instance_name;User ID=myOracleUsername;Password=myOraclePassword"
I've used this exact connection string for older version of Oracle client, but can't see any reason why it won't work for your version as well.
try this :
provider=OraOLEDB.Oracle

Why do I get an ADO connection error while using classic ASP?

I am getting an error when running this classic asp script:
Dim DB_CONNECTIONSTRING, rs, iRecordCount, strSQL
DB_CONNECTIONSTRING = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=employee;Trusted_Connection=yes;"
strSQL = "SELECT * FROM EmployeeProfiles"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQL, DB_CONNECTIONSTRING, adOpenStatic, adLockReadOnly, adCmdText
The message I am getting is (the server does exsist):
Microsoft OLE DB Provider for SQL
Server error '80004005'
[DBNETLIB][ConnectionOpen
(Connect()).]SQL Server does not exist
or access denied.
\Default.asp, line 13
I see you're using Trusted_Connection=yes in your connection string. That means that whatever identity ASP is running under will try to connect to the database server using Windows authentication. The actual identity the web server uses depends on the platform and setup (usually IUSR_Foo).
To test out if this is the issue, try using temporarily replacing the connection string with one that uses SQL authentication. If this is the issue, you may want to either configure the web server to run the ASP under a different user account which has been granted database access (preferred) or give the current web server's identity access to the database. Or you can stick with SQL authentication, of course.
Either the server you're running the ASP on doesn't have a running database server, or the database server should have an instance name. One common mistake is to forget to add the SQLEXPRESS instance name for SQLExpress installs.

Resources