SQL Server Connection String is Invalid

Synfusion Version:

I am referring to this blog post on connecting directly to sql server to get data to export to excel, specifically as follow.

I tried following:
- replace with my connection as follow with both Windows Authentication and username/password

- replace Database label with Initial Catalog

- trying to connect to cloud SQL Server and try replace with azure sql connection

I have checked that i am able to connect with the similar connection string via System.Data.SqlClient in my application ​but not through IConnectionString here


All of it return me error "Invalid Connection String".
What is the correct connection string needed or what else I am missing?

"Server=localhost;Database=TestDB;User Id=myUsername;Password=myPassword";

"Server=localhost;Database=TestDB;Integrated Security=True";


string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password = myPassword";

            string query = "SELECT * FROM Employees";

            IConnection connection = workbook.Connections.Add("SQLConnection", "Sample connection with SQL Server", connectionString, query, ExcelCommandType.Sql)

1 Reply

RS Ramya Sivakumar Syncfusion Team February 21, 2022 02:55 PM UTC

Hi T, 

Greetings from Syncfusion. 

The User Id and Passwords seem to be wrong. In the blog post, we mentioned the UserId and Password as an example. So, you need to replace that with your User Id and Password. 

Kindly provide your Database User Id and Password similar to the following code snippet and let us know if this is helpful. 

Code snippet: 
//Connection string for DataSource 
string ConnectionString = "OLEDB;Provider=Microsoft.JET.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=" + dataPath; 

//Adding a connection to the workbook 
IConnection Connection = workbook.Connections.Add("Connection1", "Sample connection with MsAccess", ConnectionString, "", ExcelCommandType.Sql); 


Kindly refer to the following link to import the data from the database and let us know if this is working properly. And please refer the different data sources and their connection string formats supported in XlsIO. 


Regards, 
Ramya. 


Loader.
Up arrow icon