And have next code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.Common;
namespace DataProviderFactory
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("******Fun with Data provider factories******");
string dp = ConfigurationManager.AppSettings["provider"];
string cnStr = ConfigurationManager.AppSettings["cnStr"];
DbProviderFactory df = DbProviderFactories.GetFactory(dp);
DbConnection con = df.CreateConnection();
Console.WriteLine("Your connection object is {0}", con.GetType().FullName);
con.ConnectionString = cnStr;
con.Open();
DbCommand com = df.CreateCommand();
Console.WriteLine("Your comand object is {0}", com.GetType().FullName);
com.Connection = con;
com.CommandText = "SELECT * FROM Debitors";
DbDataReader dr = com.ExecuteReader(CommandBehavior.CloseConnection);
Console.WriteLine("Your data reader object is a: {0}", dr.GetType().FullName);
Console.WriteLine("\n****Debitors****");
while (dr.Read())
Console.WriteLine(dr["DebitorName"]);
dr.Close();
}
}
}
But cant conect with date base, every time error:
When connecting to the SQL Server error associated with the network or with a specific instance. Server not found or is unavailable. Make sure that the instance name is correct and that SQL Server allows remote connections. (provider: named pipes provider, error: 40-could not open connection to SQL Server)
Please, help, why?
Vilas GitePosted Jul 11, 2011, 10:40 AM
Read it, Hopes will work..!
http://blog.sqlauthority.com/2008/08/24/sql-server-fix-error-40-could-not-open-a-connection-to-sql-server-fix-connection-problems-of-sql-server/]
SQL Connectivity Issue:
http://blogs.msdn.com/sql_protocols/archive/2005/10/22/483684.aspx
http://blogs.msdn.com/sql_protocols/archive/2005/10/29/486861.aspx
---------------------------------------------------------------------------------------------------
If this reply hepls yourpost…then "MARK AS ANSWER"!
Vilas GitePosted Jul 12, 2011, 4:28 AM
Suthish NairPosted Jul 11, 2011, 6:29 AM
How to find correct connection string:
Find Database Connection and Generate Connection String using Visual Studio
Jiteendra SampathiraoPosted Jul 11, 2011, 5:06 AM
Remove
add System.Data.SqlClient to ur page code behind page
Like using System.Data.SqlClient;
Remove this code
string dp = ConfigurationManager.AppSettings["provider"];
And run it...Hope it works fine.
otherwise check this Connection working or not..
Data Source=localhost:uid=sa;pwd=;Initial Catalog=NORTHWND;Integrated Security=True;