How to connect to local database using ASP classic

2019-06-12 11:13发布

问题:

I have connected to my local database through SQLSMS using the string (LocalDb)\v11.0

It opened up a connection and I could add a database.

In my ASP classic code (don't ask :( C#.NET FTW!.. damn clients) I have the following code:

objConn.ConnectionString = "Provider=SQLOLEDB;Persist Security Info=True;Data Source=(LocalDb)\v11.0;Initial Catalog=databasename"

It is returning this error: Invalid authorization specification

I have no idea what to put in for the User Id and Password parameters?

回答1:

You'll need to use SQL server authentication for this:

objConn.ConnectionString = "User ID=<sql server user id>;Password=<password for sql server user>;Initial Catalog=<database>;Data Source=<database server\instance name>;Provider=SQLOLEDB"

Actually looks like there is a previous question 'SQL Server 2012 classic asp connection string' that might cover this in more detail.



回答2:

Here's an example connection string (SQL Server 2014 on localhost):

cnstring = "Provider=SQLOLEDB.1;Data Source=.\sqlexpress;Initial Catalog=dATABASEnAME;UID=sqlsERVERUser;PWD=yourPassword;"