I am in my first steps using db in an application so my goal is to build simple db with one table from scratch in order to improve and learn
I have opened new db using the visual studio : Tolls -> connect to database and announced him to create new data base
the next step was to populate a table with 4 columns (the all 4 are nchar(10))
and then (with no actual data inside )i tried this code:
try
{
// step 1: create a SqlConnection object to connect to the
// SQL Server my server connection string proprties database
// i think the bug should be here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SqlConnection mySqlConnection = new SqlConnection("Data Source=./SQLEXPRESS;AttachDbFilename=C:/Users/STERN/Documents/myDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");//"server=localhost;database=Northwind;uid=sa;pwd=sa");
// step 2: create a SqlCommand object
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
// step 3: set the CommandText property of the SqlCommand object to
// a SQL SELECT statement that retrieves a row from the Customers table
mySqlCommand.CommandText =
"SELECT type " +
"FROM Table1 " +
"WHERE type = ‘ALFKI’";
// step 4: open the database connection using the
// Open() method of the SqlConnection object
mySqlConnection.Open();
/* some code .... */
catch (SqlException e)
{
Console.WriteLine("A SqlException was thrown");
Console.WriteLine("Number = " + e.Number);
Console.WriteLine("Message = " + e.Message);
Console.WriteLine("StackTrace:\n" + e.StackTrace);
}
string s = Console.ReadLine();
}
where the exception i get is throwen by mySqlConnection.Open(); this is the error massage i get :
A SqlException was thrown Number = 3 Message = A network-related or instance-specific error occurred while establishi ng a connection to SQL Server. The server was not found or was not accessible. V erify that the instance name is correct and that SQL Server is configured to all ow remote connections. (provider: Named Pipes Provider, error: 40 - Could not op en a connection to SQL Server) StackTrace: at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception , Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternal ConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Bool ean encrypt, Boolean trustServerCert, Boolean integratedSecurity) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeo ut, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection ow ningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnecti on owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, St ring newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdent ity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOp tions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConn ection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owning Object) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection o wningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection ownin gObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection ow ningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection ou terConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at ConsoleApplication1.Program.Main(String[] args) in C:\Users\STERN\AppData\ Local\Temporary Projects\ConsoleApplication1\Program.cs:line 29
if someone knows about pdf , article ,something that would help me it would b very nice of him to write it down here... can someone please help me....