Classic ASP connecting to localdb for SQL Server - asp-classic

Can anyone explain why this works
Conn.Open "Provider=SQLOLEDB;Server=tcp:myazurename.database.windows.net;Database=People;Uid=MyUid;Pwd=MyPwd;Encrypt=yes;"
and this doesn't
Conn.Open "Provider=SQLOLEDB;Server=(localdb)\v11.0;Database=People;Uid=MyUid;Pwd=MyPwd;Encrypt=yes;"
I copied my live azure database locally for dev work in Classic ASP and the error message is
Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).] SQL Server does not exist or access denied.
Azure SQL server version: 11.0.9231
Local SQL server version: 11.0.2318
I can connect using the same details on SQL Server Management Studio so its not a user permissions thing...
Under Security for the server, the user has public server role, the user mapping for the 'People' database is everything except db_denydatareader and db_denydatawriter.
I have also tried (localdb)\\v11.0 which doesn't make a difference.
Any ideas?

OK so I believe the answer is as follows: It doesn't like (LocalDb)\V11.0 it wants a proper instance name like you said in the first place. MACHINENAME\INSTANCENAME OR localhost\INSTANCENAME which I am using as this is going to be replicated for other devs. Also, you DONT NEED two back slashes! My problem is I somehow didn't have a local instance installed. Thanks or your help #Lankymart

Related

ASP.NET 4.5 Connection string to SQL Server 2019 - "An error occurred while communicating with the database"

So my company has an old legacy .NET 4.5 web application running on IIS (version 8.5.9600.16384) in which it's application database resides on Microsoft SQL Server 2014 (SP3)... This works perfectly fine.
However (due to decommissioning / upgrades) we want to move the database to our SQL Server 2019 Server. So I took the original .NET package and re-imported it >> during the wizard I entered the SQL Server 2019 Server / db path and renamed the solution name with '_TEST' suffix >> then restarted IIS. The resulting connection string looks like this (as expected / mirroring the original working one however with the new server / db / uname):
connection string in IIS
When I go to test logging in to the web application (via IE11), I get the following "an error occurred while communicating with the database" error after clicking login:
Error message
We also tested the same exact SQL Server 2019 connection string through Powershell on this same web server and we are able to connect into the database, so it would seem that there's some mechanism failing inside the .NET application whether there's a configuration or driver not quite right somewhere.
Does anyone have any suggestions as to what I could potentially try next or what the issue might be here?
It seems you need to use the correct connectionstring. I know it works in your previous sql server 2014. Please follow the below steps to get the connection string, and replace it in your web.config. And the settings sync to your IIS.
If there also have any errors, you can update your post.
Steps
open your vs2019, and open sql server object explorer .
Add new server, and type the information to connect your sql server 2019.
After connect to the sql server, please click the Properties to copy the Connection string.

Azure login to user db with pyodbc from a Azure webjob

I am trying to login to Azure sql server with pyodbc which logs me in a master db rather than the userdb like 'xyzdb' that i provide in the connection string. The solution to this seems changing to a DSN less based logins that needs configuring the dsn on windows machine.
But i require to run the python script with pyodbc connection from a Azure webjob so configuring dsn is not possible. Hence not able to use the user database as intended. Any solution?
After login to master db i thought to change to user db with "USE xyzdb;" Sql command to which the azure sql server responded 'USE cannot be used to switch between databases' hence xyzdb login cannot be made. I am stuck :).
I made the azure sql server with xyzdb database. Then i tried connection string for newly created server:
pyodbc.connect('Driver={ ODBC Driver 13 for SQL Server};Server=tcp:abc.database.windows.net,1433;Database=xyzdb;
Uid=ur_username;Pwd=ur_password;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;')
This connection string logged me in masterdb not in xyzdb as intended. And As Sql server are physically maintained in stack in data center interconnection is not everytime feasible unless using something as pool elastic. So 'USE xyzdb;' Sql statement from master DB was providing 'USE cannot be used for switching between databases'.
for 3 days i tried with other methods but it didn't worked,so i posted the question.Then i tried the connection string as:
pyodbc.connect('Driver={ODBC Driver 13 for SQL Server};Server=tcp:abc.database.windows.net,1433;
Uid=ur_username;Pwd=ur_password;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;Database=xyzdb')
moving the Database field at the end of the string thinking it will first make a connection with server then it will log me in database xyzdb and It logged me in the xyzdb database.It worked the first time itself.
Now if i try with any of the 2 strings above its working as expected. Don't know what was the issue?.Looks like i wasted time of others as well :). we can remove the question i presume, as i can login the userdb. Thanks.

Moving SQL Server database to production server causing login errors

First time doing this, so please be patient. I have a test server that contains Visual Studio 2010, SQL Server 2008 R2, and IIS. Thanks to everyone's help, my webpages were working perfectly. Now it's time to move everything to the production servers.
I imported the database to the production server using the SQL Import and Export Data utility - it was successful. One thing - testing server has SQL Server 2008 R2 and production server has SQL Server 2008.
I created a new user on the production server called satime. I gave this user all the same permissions as the original user. Enforce password policy, public and sysadmin for server roles, gave db_owner and public for database master, model, msdb, tempdb, and my database TimeSQL
In the database security, I gave this new user, satime, db_owner rights.
Changed all code in Visual Studio to go to new server.
Old server:
DataSource=janetdev;Initial Catalog=TimeSQL;Persist Security Info=True;User ID=sa;Password=password
New Server
Data Source=WillSQL;Initial Catalog=TimeSQL;Persist Security Info=True;User ID=satime;Password=password
Tried to debug webpage and I'm getting a login failed for user satime.
What did I miss doing? I double checked password, user settings.
New server was set up for Windows Authentication mode only, not SQL Server and Windows Authentication mode. Never even thought to check the server security. Oh well! Thanks for all your help! You made me think.

trouble connecting to LocalDB in Visual Studio

I'm going through the Contoso University tutorial found here on asp.net and can't get past the first part due to connectionString problems.
I'm getting this error message after i enter the connection string and try to view the database.
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not
found or was not accessible. Verify that the instance name is correct
and that SQL Server is configured to allow remote connections.
(provider: SQL Network Interfaces, error: 50 - Local Database Runtime
error occurred. Cannot create an automatic instance. See the Windows
Application event log for error details.
I was looking at this msdn blog which mentions the same error under the "Deploying LocalDB on IIS Server " section but i honestly have no idea what it wants me to do.
How can do i fix this error? Is it a problem with the tutorial or am I missing something?
Thanks in advance.
Any chance it is because you forgot to double-escape the backslash? Did you try this:
"Data Source=(LocalDB)\v11.0;Integrated Security=true"
Or even better, you could just use the # mark to disable character escaping for the entire connection string:
#"Data Source=(LocalDB)\v11.0;Integrated Security=true"
Here is what i do in order to fix this problem
You need to install the sql server local db
Copy the local server of your local db in case you don't know here is how to find the local server name(You need to copy the highlighted part)
Update the local server name in the connection string in the web.config file of the Contoso Project
Note that you only need to update the server name in you connection string do not replace the whole connection string with the server name.
Re run all the migration one by one like this
update-database -TargetMigration MigratonName
Build the project and run it.
Change application pool identity from ApplicationPoolIdentity to LocalSystem in IIS for your website application pool and IntgretedSecurity = true in config
will help you.

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

Resources