Connecting to MS SQL Server from OSX using ActualODBC - sql

I'm developing a cross platform (windows + OSX) application that will be used commercially. The application will need to be able to access a database (MS SQL) and show the data.
I have installed the ActualODBC trial and use the following code to connect to the server:
QString connectionTemplate = "DRIVER={Actual SQL SERVER};SERVER=%1;DATABASE=%2;";
QString connectionString = connectionTemplate.arg("192.168.1.5").arg("Clients");
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName( connectionString );
db.setUserName( "sa" );
db.setPassword( "password" );
if( db.open() )
{
QMessageBox::about( this, tr("Connection"), tr("Connected :)") );
}
however I get the error QODBC3: Unable to connect.
Any ideas what's wrong?

Turns out this was just some settings that I needed to change with the Actual SQL Server drivers!

Related

Connect to Oracle 10g

I finished my project with MSSQL 2008r2 database And vb.net
My company have oracel ERP System (oracle10g+ora6i form)
And I need to move same data from my project. To the company's system
I use
System.Data.SqlClient
library
i need way to connect my Project to erp db
You can use the connection string
string oracle_conn= "Data Source=(DESCRIPTION =(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST = server_Ip_oracle)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = database_name)));User ID=User/Schema;Password=password;Unicode=True";
and then use the code like
using (OracleConnection objConn = new OracleConnection(oracle_conn))
{
Your code here
}

How to Connect to SQL from R Studio

I use Microsoft SQL Server Management Studio on Windows 10 to connect to the following database and this is what the login screen looks like:
Server Type: Database Engine
Server Name: sqlmiprod.b298745190e.database.windows.net
Authentication: SQL Server Authentication
Login: my_user_id
Password: my_password
This recent R Studio article offers an easy way to connect to SQL Servers from R Studio using the following:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "[your driver's name]",
Server = "[your server's path]",
Database = "[your database's name]",
UID = rstudioapi::askForPassword("Database user"),
PWD = rstudioapi::askForPassword("Database password"),
Port = 1433)
I have two questions
What should I use as "[your driver's name]"?
What should I use as "[your database's name]"?
The server path I'll use is sqlmiprod.b298745190e.database.windows.net (from above) and I'll leave the port at 1433. If that's wrong please let me know.
Driver
From #Zaynul's comment and my own experience, the driver field is a text string with the name of the ODBC driver. This answer contains more details on this.
You probably want someting like:
Driver = 'ODBC Driver 17 for SQL Server' (from #Zaynul's comment)
Driver = 'ODBC Driver 11 for SQL Server' (from my own context)
Database
The default database you want to connect to. Roughly equivalent to starting an SQL script with
USE my_database
GO
If all your work will be within a single database then puts its name here.
In some contexts you should be able to leave this blank, but you then have to use the in_schema command to add the database name every time you connect to a table.
If you are working across multiple databases, I recommend putting the name of one database in, and then using the in_schema command to specify the database at every point of connection.
Example using the in_schema command (more details):
df = tbl(con, from = in_schema('database.schema', 'table'))
Though I have not tried it, if you do not have a schema then
df = tbl(con, from = in_schema('database', 'table'))
Should also work (I've been using this hack without issue for a while).

Crystal Reports - report can't connect with database

I have issue with my report. I install my app on two PCs. On first one I have SQL Server (MS SQL).
On first PC reports works. On second PC which is in same LAN report prompts me a window to set connection (which has empty, not editable database name box).
Report was created in Visual Studio 2017 with installed CRforVS 13.0.22
Client has installed CR runtime 13.0.22
I set connection programmatically using this code:
SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder(connectionString);
DataSourceConnections dataSourceConnections = reportDocument.DataSourceConnections;
foreach (IConnectionInfo connectInfo in dataSourceConnections)
{
if (csb.IntegratedSecurity)
{
connectInfo.SetConnection(csb.DataSource, csb.InitialCatalog, true);
}
else
{
connectInfo.SetConnection(csb.DataSource, csb.InitialCatalog, false);
connectInfo.SetConnection(csb.DataSource, csb.InitialCatalog, csb.UserID, csb.Password);
reportDocument.SetDatabaseLogon(csb.UserID, csb.Password);
}
}
crystalReportViewer1.ReportSource = reportDocument;
crystalReportViewer1.Zoom(1);
I don't know what am I missing. Any help will be appreciated.
Adjust the host files of the affected computer. Include the SQL Server Name and its IP.

oracle connection string not working

On a different oracle 11g server, this variant of connection string format works:
Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID))); User Id=myUsername;Password=myPassword;
but when I use this on another oracle 11g server with similar configuration, it doesn't work anymore.
When I use tnsping , the result comes out similar to the connection string above except the service name is blank.
Used EZCONNECT adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=ip address)(PORT=port)))
OK (20 msec)
The DB is also reachable using the SQL Developer. What's wrong with my connection string? I'm working with a web service made in .NET that needs to connect to the oracle DB.
I think you missed out on this part SERVER = DEDICATED
datasource =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = XXXX)(PORT = abc))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = my_orcl_db)

Failure to create a SQL Azure login with SMO

The following piece of code works with regular SQL and SMO. I'm trying to get it to work with SQL Azure. According to this MSDN article, a limited subset of functionality that I need (database and login creation) should be supported. All the business checking whether an object exists will also fail: server.Logins[loginName] != null or server.Databases.Contains(dbName). I can create a database if I dont check whether it exists or not, but i cant create a login. Anyone else ran into the same problem?
string connectionString =
"Server=tcp:XXXXXX.database.windows.net;Database=MyDatabase;User ID=XXXXXXX;Password=XXXXXX;Trusted_Connection=False;Encrypt=True;TrustServerCertificate=true;"
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
ServerConnection serverConnection = new ServerConnection(connection);
Server server = new Server(serverConnection);
Login login = new Login(server, "NewLogin");
login.LoginType = LoginType.SqlLogin;
login.Create("NewStrongPwd123***");
}
Create failed for Login 'NewLogin'.
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()
at Microsoft.SqlServer.Management.Smo.Login.Create(SecureString password)
at Microsoft.SqlServer.Management.Smo.Login.Create(String password)
Proposed answers to this question were identified on the MSDN Forum including a working approach. Please take a look at: http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/26e42082-e649-4cde-916d-c1da2275e377