waheedrafiq
Member
- Joined
- Jan 4, 2015
- Messages
- 11
- Programming Experience
- 1-3
Hi all
I have try many different sites to see if I can resolved my problem which is that I can't establish a authentication with my database
I am creating a very basic app that uses SQL database , so I install my sql server 2012 and created a basic app in c# with the following fields
userID
First Name
Surname
and a saved button.
keep getting the following error System.Data.SQLClient.sqlException = {"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}
this is what my connection strings looks like
I really don't want to use sqluser account that I created in windows and added the account in sql server manager--> login want I want to use is Windows Authentication
here is rest of my code
any advice would be very much appreciated , I also had a look at the ConnectionString.com site
I have try many different sites to see if I can resolved my problem which is that I can't establish a authentication with my database
I am creating a very basic app that uses SQL database , so I install my sql server 2012 and created a basic app in c# with the following fields
userID
First Name
Surname
and a saved button.
keep getting the following error System.Data.SQLClient.sqlException = {"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}
this is what my connection strings looks like
connection.ConnectionString = "Data Source=XBIRD/MSSQLSERVER;Initial Catalog=testingSQL.mdf;" + //"Trusted_Connection=True;"+ "User id=sqluser;" + "Password=password;";
I really don't want to use sqluser account that I created in windows and added the account in sql server manager--> login want I want to use is Windows Authentication
here is rest of my code
any advice would be very much appreciated , I also had a look at the ConnectionString.com site
private void btnSave_Click(object sender, EventArgs e) { SqlConnection connection = new SqlConnection(); //string SqlConnStr = "Data Source=XBIRD;" + // "Initial Catalog=testingSQL.mdf;" + //"Authentication=Windows Authentication;"; // "User id=MSSQLSERVER;" + //"Password=password;"; connection.ConnectionString = "Data Source=XBIRD/MSSQLSERVER;Initial Catalog=testingSQL.mdf;" + //"Trusted_Connection=True;"+ "User id=sqluser;" + "Password=password;"; connection.Open(); MessageBox.Show("connection Open"); SqlCommand cmd = new SqlCommand(); cmd.Connection = connection; cmd.Parameters.AddWithValue("@userID", txtID.Text); cmd.Parameters.AddWithValue("@Name", txtName.Text); cmd.Parameters.AddWithValue("@Surname", txtSurname.Text); cmd.CommandText = "INSERT INTO testingSQL(userID , Name, Surname) VALUES (@userID , @Name, @Surname)"; try { // connection.Open(); int rowsAffected = cmd.ExecuteNonQuery(); MessageBox.Show("Data is saved"); } catch (Exception ex) { } finally { connection.Close(); } } }
Last edited by a moderator: