vipin mudgal

vipin mudgal

  • NA
  • 7
  • 3k

How to read connection string from sql table using C#.net

Mar 16 2016 12:10 PM
                    I am using .net window form application using Ms-access database, In aceess database i                        have a table which define connection string attribute then how to fetch sql connection                            string from access database and make a new connection to get  sql database table.
                      
 
 
                             
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Mapping
{
public partial class Form1 : Form
{
private OleDbConnection Conn;
private OleDbCommand oleDbCmd = new OleDbCommand();
//parameter from mdsaputra.udl
private String connParam = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\noisuf.dtl;Persist Security Info=False";
public Form1()
{
Conn = new OleDbConnection(connParam);
InitializeComponent();
//connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\noisuf.dtl;Persist Security Info=False");
}
private void button1_Click(object sender, EventArgs e)
{
Conn.Open();
oleDbCmd.Connection = Conn;
OleDbDataAdapter dAdapter = new OleDbDataAdapter("Select ConStringname from MappingConnections", connParam);
OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
DataTable dataTable = new DataTable();
DataSet ds = new DataSet();
dAdapter.Fill(dataTable);
Conn.Close();
//string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\noisuf.dtl;Persist Security Info=False";
//string query = "Select ConStringName from MappingConnections";
//OleDbConnection conn = new OleDbConnection(connString);
//OleDbCommand cmd = new OleDbCommand(query, conn);
//conn.Open();
//// create data adapter
//OleDbDataAdapter da = new OleDbDataAdapter(cmd);
//// this will query your database and return the result to your datatable
//da.Fill(dataTable);
//conn.Close();
//da.Dispose();
}
}
}
 
          
 

Answers (1)