Connection C# & sql server 2005
Résolu
feros2184
Messages postés
10
Date d'inscription
Statut
Membre
Dernière intervention
-
snk111 -
snk111 -
Bonjour, je cherche la chaîne de connection pour me connecter à ma base de donné SQL Server 2005 avec C#.
J'ai essayé avec çà :
Mais j'obtiens ce message d'erreur :
Je n'ai pas précisé dans cette string les attributs user et password car j'ai coché l'option windows authentication quand j'ai crée ma base de donné.
Savez-vous pourquoi cette chaine de connection n'est pas valide ?
NB: je travaille sur visual studio 2008
Merciiiiiiiiiiiiiiiiii
J'ai essayé avec çà :
OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = @"provider=SQLOLEDB.1;DataSource=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\MaBase.mdf;Initial Catalog=MaBase;"; try { conn.Open(); MessageBox.Show("Base de données ouverte...."); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } conn.Close();
Mais j'obtiens ce message d'erreur :
Spécification de permission non valide Attribut de chaîne de connexion non valide
Je n'ai pas précisé dans cette string les attributs user et password car j'ai coché l'option windows authentication quand j'ai crée ma base de donné.
Savez-vous pourquoi cette chaine de connection n'est pas valide ?
NB: je travaille sur visual studio 2008
Merciiiiiiiiiiiiiiiiii
A voir également:
- Connection C# & sql server 2005
- Money 2005 - Télécharger - Comptabilité & Facturation
- Gmail connection - Guide
- Cybera server - Télécharger - Divers Réseau & Wi-Fi
- Ps3 media server - Télécharger - Divers Réseau & Wi-Fi
- Filezilla server - Télécharger - Téléchargement & Transfert
5 réponses
Je me trompe peut etre mais OleDBConnection c'est pas pour une base de donnée Access ? Pour une base de donnée SQL Server c'est SqlConnection je crois.
To connect to SQL Server from C#.NET, you need to create a connection string such as below:
private SqlConnection connection;
private string connectionString =
@"Server=(local);Database=Embedding_SQL_Test;User ID=sa;Password=123";
connection = new SqlConnection( connectionString );
Next, you use the SqlConnection object created above to create a 'SqlCommand', as shown below:
SqlCommand cmd = new SqlCommand( "select * from Customer where CustomerID = @Cid", connection);
The SQL query shown here can be replaced by a SELECT, INSERT, UPDATE queries etc.
Next to execute the SQL queries in the database, you use the following methods:
ExecuteReader - to execute SELECT queries
ExecuteNonQuery - to execute INSERT, DELETE, UPDATE, and SET statements.
This is a very short description of how to connect to SQL Server database from C# and execute SQL queries in the database.
For details about the connection string, the methods and their parameters check the following link: ( https://www.shahriarnk.com/ )
Here you will also find details about how to pass parameters to the SQL queries as well as calling stored procedures and much more.
private SqlConnection connection;
private string connectionString =
@"Server=(local);Database=Embedding_SQL_Test;User ID=sa;Password=123";
connection = new SqlConnection( connectionString );
Next, you use the SqlConnection object created above to create a 'SqlCommand', as shown below:
SqlCommand cmd = new SqlCommand( "select * from Customer where CustomerID = @Cid", connection);
The SQL query shown here can be replaced by a SELECT, INSERT, UPDATE queries etc.
Next to execute the SQL queries in the database, you use the following methods:
ExecuteReader - to execute SELECT queries
ExecuteNonQuery - to execute INSERT, DELETE, UPDATE, and SET statements.
This is a very short description of how to connect to SQL Server database from C# and execute SQL queries in the database.
For details about the connection string, the methods and their parameters check the following link: ( https://www.shahriarnk.com/ )
Here you will also find details about how to pass parameters to the SQL queries as well as calling stored procedures and much more.
Merci Melooo pour votre reponse,
j'ai deja cherché sur ce site mais j'ai pas arrivé a trouvé la solution...
toujours il m'affiche:
j'ai deja cherché sur ce site mais j'ai pas arrivé a trouvé la solution...
toujours il m'affiche:
Spécification de permission non valide Attribut de chaîne de connexion non valide
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Merci à tous
j'ai trouver la solution...
j'ai trouver la solution...
OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=SQLOLEDB;Driver={SQL Native Client};Server=SERT\\SQLEXPRESS;Database=client;Trusted_Connection=yes;"; try { conn.Open(); MessageBox.Show("Base de données ouverte...."); // Insert code to process data. } catch (Exception ex) { MessageBox.Show(ex.ToString()); }