How to write connection string to connect from classic ASP page to SQL 2008 R2? - sql-server

I connect from classic ASP page to SQL SERVER 2008 R2 with following connection string
"Data Source=(local);Initial Catalog=my_db;Persist Security Info=True;User ID=my_user;Password=my_pass;"
but I get error
Microsoft OLE DB Provider for ODBC Drivers: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I verified that my_db exists!, so what is wrong in my connection string?

The (local) name you've given for your data source is invalid. It should be an IP address, server name or server/instance name of your SQL installation.
UPDATE
If the SQL server is on the webserver you can use . to specify local. Here's an example connection string from one of my classic ASP projects:
"Provider=SQLNCLI10;Server=.;Database=my_db;Uid=user;Pwd=pass;"

You need to specify an oledb provider to prevent it trying to default to ODBC (and failing)
Provider=SQLNCLI10;Data Source=(local);Initial Catalog=my_db;User ID=XXX;Password=YYY;
(You also need the 2008 SQL Client OleDb provider installed on the machine)

try to change (local) with : 127.0.0.1

Try:
Provider=SQLNCLI10;Server=(local);Database=my_db;Uid=my_user; Pwd=my_pass;
If in doubt, check connectionstrings.com.

Related

SQL Server connection string troubles

I am working on an ASP.NET MVC project, which uses this connection string:
<add name="Name"
connectionString="Data Source=.;initial catalog=MyDBName;integrated security=True;multipleactiveresultsets=True;" />```
Note: the data source value is ., this works but after I reset my pc and reinstalled SQL Server, it no longer works, I get an error
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.
until I change the . in the connection string to DESKTOP-1V12LN7\SQLEXPRESS.
My question is what does the value . in the connection string mean and why doesn't it work after reinstalling SQL Server?
The data source=. (or server=. or data source=(local), which are all equivalent) means : connect to the local machine and the default, unnamed instance of SQL Server - this is the default for all non-Express editions of SQL Server installed on your machine.
When you install SQL Server Express, by default, it doesn't get installed as the default, unnamed instance - but it uses a SQLEXPRESS instance name - so you need to change your connection string to:
.\SQLEXPRESS
(local)\SQLEXPRESS
DESKTOP-1V12LN7\SQLEXPRESS

What is the connection string to connect to local db file (.mdf)

I use the following connection string to connect to database in the sqlserver instance SQLEXPRESS:
QString connStr = "DRIVER={SQL SERVER};SERVER=%1;DATABASE=%2;";
But I want now to connect to SQL Server database file (.mdf) and I already installed Microsoft SQL Server 2016 LocalDB. What connection string should I use?
I tried the following connection string:
QString connStr = "DRIVER={SQL SERVER};SERVER=%1;AttachDbFileName=%2;"
db.setDatabaseName(connStr.arg("(LocalDB)\\v11.0",dbFilename));
And I also tried a different server:
db.setDatabaseName(connStr.arg("(LocalDB)\\MSSQLLocalDB",dbFilename));
But none of them works and throw the same error:
"[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not
exist or access denied. [Microsoft][ODBC SQL Server
Driver][DBNETLIB]ConnectionOpen (Connect()). QODBC3: Unable to
connect"
After some researches I found the solution:
1- Ensure that Microsoft SQL Server 2016 LocalDB is installed.
2- Change the 'Driver' in the connection string to:
DRIVER={ODBC Driver 13 for SQL Server}
3- Ensure the attribute 'AttachDbFileName' points to the correct database file path, especially you need to pay attention to the path separator whereas QT use "/" but in Windows you have to use "\" ("\\") <-- (This is was my main problem).
To get rid of this problem use QDir::toNativeSeparators(dbFilename).
So and after those changes the connection string will be like this:
QString connStr = "DRIVER={ODBC Driver 13 for SQL Server};SERVER=%1;AttachDbFilename=%2;Integrated Security=true;";
db.setDatabaseName(connStr.arg("(localdb)\\MSSQLLocalDB").arg(dbFilename));
Thanks.

Lazarus (Pascal) How to connect to SQL Server using ODBC or TMSSQLConnection?

I am using SQL Server 2008 R2 and my PC is 32 bit. I created an ODBC Data Source in the "Administrative Tools". I used the server name (My PC name)\SQL2008R2 which is the instance name and I used Windows Authentication instead of using username and password.
In Lazarus, I used the ODBC Connection and when I try to set the property "Connected" to true I get this error:
And I tried to use also the SQL Server connection with the "dblib.dll" and got an error.
Note: I tried to paste the dll file in C:\Windows\System32 folder and in the C:\lazarus but still getting same error.
I've no experience with Pascal/Lazarus, but the ODBC error message in the first screenshot suggests that the property names in the Lazarus configuration screen don't match the property names used by ODBC; the error says:
Could not connect with connection string "DSN=jbs..."
Based on the screenshot of your ODBC system DSN, the DSN name is DBSource. Try setting value of the DatabaseName to DBSource in the Lazarus ODBC connection configuration screen.

Setting up/troubleshooting ODBC connection for SQL Server 2014

I've set up ODBC connections to databases before, but I'm currently having problems and can't seem to figure out what I'm missing. This isn't my area of expertise, and the Microsoft help/documentation is less than 'user friendly'. Appreciate any pointers.
I have a locally running instance of SQL Server 2014, with a couple of test databases I'm using to develop another application. Here's the info on the setup:
SELECT HOST_NAME() AS 'host_name()',
##servername AS 'ServerName\InstanceName',
SERVERPROPERTY('servername') AS 'ServerName',
SERVERPROPERTY('machinename') AS 'Windows_Name',
SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS 'NetBIOS_Name',
SERVERPROPERTY('instanceName') AS 'InstanceName',
SERVERPROPERTY('IsClustered') AS 'IsClustered'
query returns:
host_name() ServerName\InstanceName ServerName Windows_Name NetBIOS_Name InstanceName IsClustered
DECATHLETE DECATHLETE\SQLEXPRESS DECATHLETE\SQLEXPRESS DECATHLETE DECATHLETE SQLEXPRESS 0
In the Windows ODBC Data Source Administrator (64-bit) - I'm running W10 in a VMWare VM on Mac, btw - the server shows up as available when I try to configure a new System DSN. Following is the setup info:
Microsoft ODBC Driver for SQL Server Version 12.00.2000
Data Source Name: TEST
Data Source Description:
Server: DECATHLETE
Use Integrated Security: Yes
Database: (Default)
Language: (Default)
Data Encryption: No
Trust Server Certificate: No
Multiple Active Result Sets(MARS): No
Translate Character Data: Yes
Log Long Running Queries: No
Log Driver Statistics: No
Use Regional Settings: No
Use ANSI Quoted Identifiers: Yes
Use ANSI Null, Paddings and Warnings: Yes
Testing connectivity generates the following error message:
Microsoft ODBC Driver for SQL Server Version 12.00.2000
Running connectivity tests...
Attempting connection
[Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [2].
[Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
[Microsoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
TESTS FAILED!
I've confirmed access to the databases from SQL Server Management Studio. The login uses windows authentication with no password. I can get in, play with databases, run queries, etc. (See picture below).
I'm at a loss. I'd previously created ODBC connections with no problems. This seems to have cropped up as an issue since upgrading the virtual machine from W7 to W10. Hoping someone can point out an obvious oversight.
* Update *
Adding a screenshot of the ODBC configuration wizard below. Note that the SQL Server is showing up in the list of available servers on the wizard. So it seems to be seeing the server but failing to connect to it.
In the "Create a New Data Source to SQL Server" dialog/window, the incorrect "Server name:" is specified. Since you have a named instance of SQL Server, type in the name of the SQL Server host, a backslash, and the instance name. Here is the format: SQLHostName\SQLInstanceName.
Please check, whether you're allowing remote connections to the SQL Server using the 'Microsoft Sql Server 2014\Configuration Tools\Sql Server Configuration Tool' utility.
Go to Sql Server Network Configuration and make sure you allow TCP/IP for remote connections.
Also I'd try to play with Windows Firewall on the Sql Server PC.
I've been searching for a solution to this issue for a while now. I am trying to link SQL tables on another server to a Microsoft Access front end to make use of the Forms for data entry etc.
The comments here solved the issue and I thought I would provide a consolidated solution for clarity:
From the SQL Server Connection Manager:
Enable SQL Server Browser
From 'SQL Server Services', modify the Properties of the 'SQL Server Browser' and set the 'Start Mode' to 'Automatic'. Apply the changes and exit.
Start the 'SQL Server Browser'.
Enable TCP/IP
From 'SQL Server Network Configuration' -> 'Protocols for [your server name]', then enable TCP/IP.
Then create an ODBC connection from your local computer. From there I used the named ODBC connection in access to link the tables I needed.

SQL Server CE connection string for OleDB

Connection string problem: I need to connect to SQL Server CE 3.5 using oledb as I want to use tabledirect function
Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;
Data Source=D:\Projects\SQLCE\AisDT.sdf;
Password=GMT786;
Persist Security Info=false;
Max Database Size=4000;
This is the connection string I am using to connect Visual Studio 2013 to SQL Server CE 3.5, but when I try to open the connection, I get following error:
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
I have checked registry too and there is no problem in registry. I think I am missing some thing in connection string
Please check my connection string as I am new to SQL Server CE.

Resources