Hi,

I have the database of the application i am doing stored in the bin. Now i want to make a new connection how can i do so?

Recommended Answers

All 5 Replies

Since no database type was specified, I'll make this generic.
Assuming you have an ODBC data source and it is set up in your Odbc Administrator...

using System;
using System.Data.Odbc;

namespace Dani_368900
{
   class Program
   {
      static void Main(string[] args)
      {
         using (OdbcConnection conn = new OdbcConnection("DSN=..."))
         {
            conn.Open();
            string strSQL = "some SQL HERE ... select asdf from T where ...";
            OdbcCommand cmd = new OdbcCommand(strSQL, conn);
            using (OdbcDataReader rdr = cmd.ExecuteReader())
            {
               while (rdr.Read())
               {
                  Console.WriteLine(rdr[0]); // or use rdr["COLUMN_NAME"].ToString();
               }

               rdr.Close();
            }

            conn.Close();
         }
      }
   }
}

which database you have?

Since no database type was specified, I'll make this generic.
Assuming you have an ODBC data source and it is set up in your Odbc Administrator...

using System;
using System.Data.Odbc;

namespace Dani_368900
{
   class Program
   {
      static void Main(string[] args)
      {
         using (OdbcConnection conn = new OdbcConnection("DSN=..."))
         {
            conn.Open();
            string strSQL = "some SQL HERE ... select asdf from T where ...";
            OdbcCommand cmd = new OdbcCommand(strSQL, conn);
            using (OdbcDataReader rdr = cmd.ExecuteReader())
            {
               while (rdr.Read())
               {
                  Console.WriteLine(rdr[0]); // or use rdr["COLUMN_NAME"].ToString();
               }

               rdr.Close();
            }

            conn.Close();
         }
      }
   }
}

no i know how to do that.. I want to do the connection where it generates the connection string.

which database you have?

I have a database (SQL Server) one and it's extenstion is *.mdf

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.