I got an ASP-Classic Page from 2001.
I upgraded/migrated the Database to an actual SQL Server Version (2016).
My problem is, when I try to connect to the database I always get an error message, that I cannot connect to the server because of the given user. I created a user on my SQL Server, this is the one I want to use for the connection but it doesn't work.
Here's the code:
Provider=sqloledb;Data Source=localhost\SQLEXPRESS;Initial Catalog=LV; User ID=lvsupervisor;Password=analogis;
The login credentials are correct. Maybe someone can help me here.
ASP Classic 3 itself works smoothly even with latest version of MS SQL (2019).
My problem is, when I try to connect to the database I always get an error message, that I cannot connect to the server because of the given user.
First of all verify that user itself able to login to MS SQL Server. Run MS SQL Management Studio and try to login to server by using user credential you have. Does it works? Could you see data in Tables?
migrated the Database to an actual SQL Server Version (2016)
Connection string: try different provider, for example Provider=SQLOLEDB.1
Delete your current DSN and create a new one using "SQL Server Authentication" instead of "Windows Authentication". Create a new user with admin/read/write permissions and nominate that account for the new DSN connection. Use a 64-bit DSN for default server or if you have enabled 32-bit applications for the site, then you must use a 32-bit DSN connection. Then you can use...
strConnection = "DSN=ExampleName;DRIVER={SQL Server};UID=ExampleUser;PWD=ExamplePass"
Set dbConnection = server.CreateObject("ADODB.Connection")
dbConnection.ConnectionString = strConnection
dbConnection.Open
SQLFunction = "SELECT ID FROM Example Where CExample.Key = '" & strInputCom & "' "
Set rsFunction = dbConnection.Execute(SQLFunction)
if not rsFunction.EOF then
strClientId = rsFunction("ID").value
else
strClientId = ""
end if
rsFunction.Close
Set rsFunction = Nothing
Related
I installed SQL Server 2017 Express on Windows 10. I couldn't get it to connect using adodb. I am able to connect to it from SQL Server Management Studio, I can query the tables, etc, it works fine, but not from asp.
This is from my asp classic code:
connectionString="Provider=SQLNCLI11;Server=LENOVO\SQLEXPRESS;Database=mydb;Trusted_Connection=yes;"
set cn=server.createobject("adodb.connection")
cn.open (connectionString)
I can't figure out what would be the reason. It connects when I use 'master' instead of 'mydb'. I created a new database with some new tables.
It may not be related, but I don't have a password for windows, this is my personal computer so I didn't want to have login credentials. I'm not sure if that could be the reason. I didn't try creating a user, but if that's what is the issue here I will create one.
It worked, I went into the Security\Logins -> BUILTIN\Users -> Properties -> User Mapping -> checked 'mydb' -> checked db_accessadmin and db_owner. Tried my asp code again, it worked.
Trying to connect a classic asp page to sql server express 2014 using a dsn.
I've created a new database (in sql server management studio) called warehouse, with a table called users. I've added a new login called user1 with a password and mapped it to the warehouse database
I've created an ODBC System DSN on the same machine, using sql server native client 11 driver called SQLServer2 with integrated windows authentication, and a default database warehouse. Testing the connection at this point works fine!
On the ASP page I'm using:-
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "dsn=SQLServer2;uid=user1;pwd=xyz;"
Error:- Microsoft OLE DB Provider for ODBC Drivers error '80040e4d'
[Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open
database "warehouse" requested by the login. The login failed.
I'm pretty sure that its a permissions issue and that the connection string is OK otherwise but after hours and hours of trying different strings, different users, I can't seem to get the damn thing to connect
If Anyone can throw any ideas my way I'd be very grateful. Thanks!
The way you are describing the problem the DSN uses integrated security so your credentials might be ignored and the database is called using the application pool identity.
If you have no specific reason why you need to use a DSN I would recommend using a connection string like the following:
objConn.Open "Provider=sqloledb;Server=yourdbserver;uid=user1;pwd=xyz;Database=warehouse"
A look into your SQL server log might give you a hint as to which user is actually failing to connect to your database.
I think you should have done something like this
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString "dsn=SQLServer2;uid=user1;pwd=xyz;"
objConn.open
I want to test a connection using SQL Server that can access through internet but I'm lost, I don't know where to start.
I know how to do it in MySQL but I want to know how to do it in SQL Server.
Thanks in advance.
One quick trick I know of, which works even on machines without SQL tools installed:
Create a new blank file somewhere and give it .udl for an extension. It should change to an icon with a table and a white page with 0s and 1s in the background.
Double-click on it to open the "Data Link Properties" dialog
On the Provider tab, choose "Microsoft OLEDB Provider for SQL Server"
On the Connection tab, fill in the remote server details and credentials
Click "Test Connection"
Where to start?
Try looking for the correct connection string here
You then need to find an example using the System.Data.SqlClient
By 'connect through the internet' do you mean connect from the internet to a SQL Server?
You need to open appropriate ports in the firewall and NAT them to your SQL Server.
To get you started, I would install a copy of SQL Server Express onto your local workstation and create an SQL Server instance with SQL Server Authentication. Also install SQL Server Management Studio which is a visual console through which you can manage your database and logins etc. They are available for free here:
http://www.microsoft.com/en-us/download/details.aspx?id=29062
Go into SQL Server Management Studio, create a database and a login username and password with sysadmin rights. Connect using the following code. The principles are similar to connect to an SQL Server database over the internet only there are more security issues to take into account.
Dim sConnectionString As String = "Server= MYCOMPUTERNAME\SQLEXPRESS;Database=DATABASE_NAME;User ID=USER_ID;Password=PASSWORD;Trusted_Connection=False;
Try
Dim mySqlConnection As New System.Data.SqlClient.SqlConnection()
mySqlConnection.ConnectionString = sConnectionString
mySqlConnection.Open()
MessageBox.Show("You have connected successfully to the SQL Server database.")
Catch SqlEx As SqlException
MessageBox.Show(SqlEx.Message & Constants.vbNewLine & Constants.vbNewLine & "You have NOT connected successfully to the SQL Server database.")
Catch ex As Exception
MessageBox.Show(ex.Message & Constants.vbNewLine & Constants.vbNewLine & "You have NOT connected successfully to the SQL Server database.")
End Try
I have a SQL Server 2012 Express installation with a new DB called BRD that I have created. I have also created a test table (tempDemo), and a test stored procedure (getStList) in the BRD database. The stored procedure works when I run it in the query window so I believe the table and stored procedure are legit. The SQL Server is set to "SQL Server and Windows Authentication mode".
I then attempted to create a Classic ASP page that then connected to the SQL Server using the following connection string:
objConn.ConnectionString="Provider=SQLOLEDB;Server=XPSI7\SQLEXPRESS;Database=BRD;Integrated Security=SSPI;"
This fails with the following message:
"Microsoft OLE DB Provider for SQL Server error '80004005'
Cannot open database "BRD" requested by the login. The login failed."
When I change the database to MASTER instead of BRD the ASP page does not error out. I'm just testing the connection string by opening it and then closing it, but it appears to work.
I've looked at the security settings for MASTER and BRD in the Object Explorer, but have failed to notice a difference. I've also looked at the IIS_IUSRS for the folders, but no difference either - not sure if this is necessary anyway.
SQL Server authenticates your login at the server level. Then it tries to open the database you've asked to connect to. At this point, you need to either map a database-level user to the server-level login, or use a server-level login that inherently has sufficient privileges to use the database.
A simple (but not secure) way to demonstrate this using SQL Server Authentication:
USE master;
GO
CREATE LOGIN foo
WITH PASSWORD = 'bar', CHECK_POLICY = OFF;
GO
USE BRD;
GO
CREATE USER foo FROM LOGIN foo;
GO
EXEC sp_addrolemember N'db_owner', N'foo';
GO
Now in your ASP connection string, use:
objConn.ConnectionString = "Provider=SQLNCLI;Data Source=XPSI7\SQLEXPRESS;Initial Catalog=BRD;User ID=foo;Password=bar;"
You can also map whatever login you're using to a database user simply doing:
USE BRD;
GO
CREATE USER [YourDomain\IIS_IUSRwhatever]
FROM LOGIN [YourDomain\IIS_IUSRwhatever];
GO
That will grant them access to the database, but it will be up to you to decide what permissions to grant. This assumes that you are allowing anonymous access to the web server; if IIS is challenging and accepting Windows authentication, you'll need to do the above for the user(s) that will be submitting their credentials. In either case you should be able to continue using the connection string you have now.
Try the following connection string:
strConnection = "Provider=SQLNCLI10;Server=server_name;Database=" & BD_REMOTE_INITIAL_CATALOG & ";Uid=" & BD_REMOTE_USER_ID & "; Pwd=*****;"
I've created a linked server to an Excel spreedsheet. It's ok and working in SQL Server I can query excel file in query analyzer.
But when I'm trying to access this link server in my asp page:
Set pishbini = Server.CreateObject("ADODB.Recordset")
pishbini.ActiveConnection = MM_semmet_STRING
pishbini.Source = "SELECT * FROM OPENQUERY(SemnanmetWeekly, 'SELECT * FROM [DayPish$]')"
pishbini.CursorType = 0
pishbini.CursorLocation = 2
pishbini.LockType = 1
pishbini.Open()
SemnanmetWeekly is the name of linked server in SQL Server I'm getting this error in my asp page:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]OLE DB provider
"Microsoft.Jet.OLEDB.4.0" for linked server "SemnanmetWeekly" returned
message "Cannot start your application. The workgroup information file
is missing or opened exclusively by another user.".
/Daypish.asp, line 15
IUSR (IIS user) has full access to excel file, I have played with all the different options in in my Link Server Options like impersonating or accessing excel file with administrator account, but error remained the same!
I prefer to not change the code, since I'm only doing administration stuff on this server. it has been working on an old server but since we moved it to new server it stopped working. anything I'm missing here?
Not related to permissions. I think you logged in to Sql Server with Windows Authentication, everything is okay, you're the boss. But, if the connection in ASP is SQL authenticated, you get this error. So, you should add a linked server login with a query similar to following.
Exec master..sp_addlinkedsrvlogin
#rmtsrvname = N'SemnanmetWeekly',
#useself = N'False',
#locallogin = N'sa', /* replace your own - same as sql server authenticated account */
#rmtuser = NULL,
#rmtpassword = NULL
Then you can connect to SemnanmetWeekly in your ASP application.