Darw1n34
Darw1n34

Reputation: 332

Export SQL Server data into a specific sheet in Excel

I am trying to replicate a defunct homegrown program that I don't have access to the source code. Basically I need to read in a SQL file (here denoted as querySqlAddresses[i]), execute it and dump the result into a specific sheet in a file that I have open.

I'm finding a lot of dead end things, but I think there may be promise in this, I am just not sure HOW to drop the "results" or even what the "results" variable is so I can target it. Does this even make sense?

string sqlConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True";
FileInfo file = new FileInfo(querySqlAddresses[i]);
string script = file.OpenText().ReadToEnd();

SqlConnection conn = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script); 

Upvotes: 1

Views: 116

Answers (1)

Darw1n34
Darw1n34

Reputation: 332

I actually found another way of doing it using OleDB connections and passing the User Name, Password and Table space into the connection string.

        string connectionString = "Provider=OraOLEDB.Oracle;Data Source=" + tableSpace + ";User Id=" + userName + ";Password=" + password + ";";
        System.Data.OleDb.OleDbConnection cnn = new System.Data.OleDb.OleDbConnection(connectionString);
        cnn.Open();
        System.Data.OleDb.OleDbDataAdapter Dadpt = new System.Data.OleDb.OleDbDataAdapter(readText, cnn);
        DataSet ds = new DataSet();
        Dadpt.Fill(ds);
        cnn.Close();

Upvotes: 1

Related Questions