I'm trying to connect to SQL Server 2008 from a Classic ASP page:
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "
Provider= SQLOLEDB.1
DataBase= MYDBNAME
Server= SERVERNAME\INSTANCE
Integrated Security = True
Trusted_Connection=Yes
Persist Security Info = False"
conn.Open -> error 80040e21 Multiple-step OLEDB operation generated errors
sql = "select * from UsersQuery where ID=" & ID
Set rs = conn.Execute(sql)
In SQL Server Log I can see that the connection was successful:
Login succeeded for user 'dbuser' Connection made using Windows
Authentication.
What is causing the error?
Thank You.
Does it works ?
Provider=SQLNCLI11;Server=ServerName\Instance;Database=MYDBNAME;Integrated Security=SSPI;DataTypeCompatibility=80;MARS Connection=True;
Related
I'm having difficulty making a connection to my MS SQL Server from R.
I believe I'm using the right driver, I checked what drivers I had listed and picked the same one that I'm using in DBeaver for the connection to the same database:
odbcListDrivers() %>% filter(name %like% "SQL Server" & !name %like% "Teradata")
My connection string looks as follow:
db_conn <- DBI::dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "Server_address",
Database = "Database_Name",
UID = "myName",
PWD = "myPWd",
Trusted_Connection = "True",
Port = 1433,
ApplicationIntent = "ReadOnly"
)
I get the following error:
Error: nanodbc/nanodbc.cpp:1021: 01S00: [Microsoft][ODBC SQL Server Driver][SQL Server]The target database ('Database_Name') is in an availability group and is currently accessible for connections when the application intent is set to read only. For more information about application intent, see SQL Server Books Online. [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute
I can connect to the same database using DBeaver and have specified the the connection has applicationIntent = readonly
Is there some other connection string property I need to include to make a connection?
Turns out that I was using the correct connection string properties but the server was running in cluster mode and therefore I needed to append 'CLS' to my database name.
My final connection string looks as follows:
db_conn <- DBI::dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "SomeDBcls.xx.yy.zz.com",
Database = "NameOfSchema",
UID = "TheGoat",
PWD = rstudioapi::askForPassword("Database password"),
Trusted_Connection = "Yes",
Port = 1433,
applicationIntent = "readonly"
)
We are upgrading our servers and .net application from windows 2000 to the newly-purchased windows 2012R2 servers. There is one function which works in windows 2000 but doesn’t work in windows 2012R2.
We are running an .net 2.0 internal application in windows 2000 and IIS 5.0 using Visual Studio professional 2015. There is one function in this application which will make a function call to an AD server using LDAP to check the login id and password in Active Directory. It is running perfectly fine before. However, once I upgrade to this new window2012R2 server running .net 2.0, it doesn’t work. The function in the application is not able to get authorization in the Active Directory. The function as below:
Private Function IsAuthenticatedByAD(ByVal sUid As String, ByVal sPwd As String) As Boolean
Dim direntRoot As DirectoryEntry, direntUsr As DirectoryEntry
Dim sDomain As String, sDomainAndUid As String
Dim dirsrchUsr As DirectorySearcher, oNative As Object
direntRoot = New DirectoryEntry("LDAP://rootDSE")
sDomain = direntRoot.Properties("DefaultNamingContext")(0)
sDomainAndUid = String.Format("{0}\{1}", sDomain, sUid)
direntUsr = New DirectoryEntry(direntRoot.Path, sDomainAndUid, sPwd)
Try
oNative = direntUsr.NativeObject
Catch ex As Exception
Return False
End Try
Return True
End Function
I received error message in the "Try" section when run oNative = ....
The error message as below:
"System.DirectoryServices.DirectoryServicesCOMException (0x8007052E):
The user name or password is incorrect." & vbCrLf & vbCrLf & " at
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)" &
vbCrLf & " at System.DirectoryServices.DirectoryEntry.Bind()" &
vbCrLf & " at
System.DirectoryServices.DirectoryEntry.get_NativeObject()" & vbCrLf &
" at ums.business.UsrMgmtBus.IsAuthenticatedByAD(String sUid, String
sPwd) in C:\inetpub\wwwroot\ums\business\UsrMgmtBus.vb:line 127"
Please help. Thanks a lot.
Am trying to run daily sql job which sends mail to my client using SMTP Server and CDONT Mail objects . Already has the code which works fine for me. Recently i have upgraded the my server from microsoft Server 2003 to 2012 and Sql server 2005 to 2014.
This code below works fine in Classic asp in server. But in sql job getting error
Set objEMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "hi#xx.in"
objEMail.From ="hello#yy.com"
objEMail.Subject = "Email subject goes here"
objEMail.HTMLBody = "Hi Sql job data"
objEMail.Send
Set objEMail = Nothing
Executed as user: NT Service\SQLSERVERAGENT. Error Code: 0 Error Source= Microsoft VBScript runtime error Error Description: Object required: 'Server' #
Server is an object that is specific to ASP Classic.
Your code is probably run by the Windows Script Host (wscript.exe / cscript.exe), which has its own CreateObject function.
Simply remove the Server. to make it work.
Set objEMail = CreateObject("CDO.Message")
Set objConfig = CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "hi#xx.in"
objEMail.From ="hello#yy.com"
objEMail.Subject = "Email subject goes here"
objEMail.HTMLBody = "Hi Sql job data"
objEMail.Send
Set objEMail = Nothing
For the record, the Server is optional in ASP Classic as well, the above code would work in both environments.
I'm looking for the best way to connect to a Heroku Postgres database from an outside application. The application is in asp.net. I am trying to use NpgSQL but am getting a certificate unknown error. Has anyone done that? Do you have any pointers?
I use this to "translate" the DATABASE_URL to a connection string
var databaseUrl = Environment.GetEnvironmentVariable("DATABASE_URL");
var databaseUri = new Uri(databaseUrl);
var userInfo = databaseUri.UserInfo.Split(':');
var builder = new NpgsqlConnectionStringBuilder
{
Host = databaseUri.Host,
Port = databaseUri.Port,
Username = userInfo[0],
Password = userInfo[1],
Database = databaseUri.LocalPath.TrimStart('/')
};
return builder.ToString();
I am using the following connection string to connect to Heroku Postgres Database:
string connString = "User ID=<user>;Password=<pass>;Host=<host>;Port=<port>;Database=<database>;Pooling=true;Use SSL Stream=True;SSL Mode=Require;TrustServerCertificate=True;"
where <user>, <pass>, <host>, <port> and <database> are values from heroku postgres app settings. Port is 5432 by default.
Then using NpgSql I create instance of NpgsqlConnection:
var conn = new NpgsqlConnection(connString);
Dafault sample: http://www.npgsql.org/doc/index.html
I am using VS 2008 .NET 3.5 & have a SQL Server database file in App_Data. When I click on "Test Connection" of database it succeeds. When I try to connect it through code, it fails. After trying to find & solve the problem reading so many sites, I think I am confused with the connection string.
My code is :
string sql = "select count(*) from LoginDB where loginUserName = #userName and loginPassword = #password";
string conStr = ConfigurationManager.ConnectionStrings["VinciConnectionString"].ConnectionString;
statusLbl.Text += "\n Conn Str = " + conStr;
conn = new SqlConnection(conStr);
statusLbl.Text += "\n Executed Conn : " + conn.ToString();
SqlCommand cmd = new SqlCommand(sql, conn);
statusLbl.Text += "\nconn DB = " + conn.Database;
In the output I get :
Conn Str = server=localhost;database=VincitoreDB.mdf;uid=VTSONY\Vikram10;Password=000;
Executed Conn : System.Data.SqlClient.SqlConnection
conn DB = VincitoreDB.mdf
SQL = System.Data.SqlClient.SqlCommand
The error message that I get here is :
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
The DB "Modify Properties"-"Advanced" tab shows this :
Original connection string was :
<connectionStrings>
<add name="VinciConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\VincitoreDB.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
After trial & error, right now it's :
<connectionStrings>
<add name="VinciConnectionString"
connectionString="server=localhost;database=VincitoreDB.mdf;uid=VTSONY\Vikram10;Password=000;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Can anyone please help me figure out what & why am not able to connect to the database? Have spend lots of hrs trying to figure out reading lots of forums, but no success. If this the problem of connection string or something else?
Please help me out. Any help is highly appreciated.
Thanks
Enable in your Sql Server Configuration manager under SQL Server Networki configuration > Protocols fro SQLExpress > TCP IP - Enabled after this restart the computer or the service.
In connection string provide your computers name for example: MY-PC\SQLEXPRESS