hello.
I want to connect MS SQL with asp.net framework 2.0
using Windows 7, IIS 7.0, Visual Studio 2010. Also using programming language C#.
Thanks.
11 replies to this topic
#1
Posted 10 February 2011 - 11:06 AM
|
|
|
#2
Posted 10 February 2011 - 10:34 PM
There appears to be a nice tutorial here:
Connecting to MSSQL Server in ASP.NET
I am sure there is great documentation on Microsoft's MSDN network.
Connecting to MSSQL Server in ASP.NET
I am sure there is great documentation on Microsoft's MSDN network.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 11 February 2011 - 12:48 AM
Alexandre
Thanks.
Here I learn how to connect MS SQL Server, do you know how to connect mdf (*.mdf) file?
I think I have problem with connection string.
Thanks.
Here I learn how to connect MS SQL Server, do you know how to connect mdf (*.mdf) file?
I think I have problem with connection string.
#4
Posted 11 February 2011 - 02:12 AM
What does yours look like? It may be something like this that should work:
SQL Server 2008 Connection String Samples - ConnectionStrings.com
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;There are some more connection string examples here:
SQL Server 2008 Connection String Samples - ConnectionStrings.com
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#5
Posted 11 February 2011 - 02:48 AM
I want to connect MS SQL.
Also, cant connect SQL Server 2005 :|
Line 17: SqlConnection con = new SqlConnection("Server=.\\SQLExpress;AttachDbFilename=|DataDirectory|Database.mdf;Database=Users; Trusted_Connection=Yes;");
Line 18: con.Open();
Line 19: con.Close();
Error on line 18Also, cant connect SQL Server 2005 :|
#6
Posted 13 February 2011 - 08:57 PM
Hmm could you copy the exception message and paste it in here, wrap the above code in try catch in catch block publish the message so that you can copy it
#7
Posted 14 February 2011 - 05:58 AM
Quote
private void asd(){
SqlConnection con = new SqlConnection("Data Source = Niko-PC\\Niko;Initial Catalog = master; Integrated Security = true;");
try{
con.Open();
con.Close();
}
catch(Exception e){
loutput.Text = e.ToString();
}
}
SqlConnection con = new SqlConnection("Data Source = Niko-PC\\Niko;Initial Catalog = master; Integrated Security = true;");
try{
con.Open();
con.Close();
}
catch(Exception e){
loutput.Text = e.ToString();
}
}
Quote
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at _Default.asd() in d:\IIS\Start\www\Default.aspx.cs:line 28
......
#8
Posted 14 February 2011 - 06:32 AM
ok just a few questions,
What is the instance name of SqlExpress that you are running,
Is it Niko? If yes i also want you to do this,
Open the Service Manager Start + Run = services.msc and hit enter
Go to Sql server browser and start the service. Set it to automatic.
Now try again
What is the instance name of SqlExpress that you are running,
Is it Niko? If yes i also want you to do this,
Open the Service Manager Start + Run = services.msc and hit enter
Go to Sql server browser and start the service. Set it to automatic.
Now try again
#9
Posted 14 February 2011 - 06:48 AM
gokuajmes
Thanks! instance name is SqlExpress ... That was reason.
Thanks again.
Thanks! instance name is SqlExpress ... That was reason.
Thanks again.
#10
Posted 14 February 2011 - 06:50 AM
You are welcome have a happy day
#11
Posted 14 February 2011 - 11:46 AM
I connected to Sql Server, but now I need to allow new Database (which I made).
#12
Posted 15 February 2011 - 01:46 AM
I did it.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









