Connection String i Web.Config Dosyasında Saklamak!

16 03 2007

ilgili yazının güncel hali için lütfen

http://www.sadullahkeles.com/2007/03/16/connection-string-i-webconfig-dosyasinda-saklamak/

adresini ziyaret ediniz..

Eğer ConnectionStringinizi Web.Config dosyasında saklayıp buradan kullanmak istiyorsanız öncelikle yapmanız gereken işlem Web.Config dosyasına şu satırları eklemek olacaktır. (Not : using kısmına using System.Web.Configuration; satırını eklemeyi unutmayın :))

<connectionStrings>
<add name=”denemeConnectionString” connectionString=”Data Source=SADULLAH\sqlexpress;Initial Catalog=deneme;Integrated Security=True” providerName=”System.Data.SqlClient” />
</connectionStrings>

Bu işlemi yaptıktan sonra .cs dosyanızdan

WebConfigurationManager.ConnectionStrings[“denemeConnectionString”].ToString();
şeklinde connectionstringinize ulaşabiliriz🙂


İşlemler

Information

8 responses

2 04 2007
Onur Aykac

System.Web.Configuration
NameSpace’ini unutmamak gerek🙂

2 04 2007
Sadullah KELEŞ

kardeşim özel mesaj atıp söylesene karizmayı ne çiziyon😛 . Unuttuğum başka neler vardır kimbilir.. Düzelttiğin için teşekkür ederim Onur. (hemen onuda ekliyim)

4 04 2007
Onur Aykac

Özel mesaj kotanı doldurmuş[sun][um] (:
Msn yerine özel mesajı kullandığımız içindir.

4 04 2007
Sadullah KELEŞ

Onur sende Ajax için hazırlasana bi blog. zevki bir işmiş ya askerden gelince büyütmeyi planlıyorum😛

7 04 2007
Onur Aykaç

Hazır bloglara pek yanaşmak istemiyorum, kendim yazmam içinde zaman yok🙂 yani blog işi benim yatar. Ajax acayip zevklidir. Webi ajax sevdirdi desem yeridir

Sloganımız;
Sıfır Post !
🙂

16 04 2014
Poll123

ARKADAŞLAR appdata içindeki bir veritabanı ismi alisveris buna nasıl bağlanabilirim lütfen yardım edin

22 03 2016
serhat

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)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: 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)

Source Error:

Line 20: String sorgu = “Select * from KoseYazilari order by KoseYazilariTarih”;
Line 21: SqlCommand cmd = new SqlCommand(sorgu, cnn);
Line 22: cnn.Open();
Line 23: SqlDataReader dr = cmd.ExecuteReader();
Line 24:

Source File: c:\inetpub\vhosts\egitimderehberlik.net\httpdocs\MasterPage.master.cs Line: 22

Stack Trace:

[SqlException (0x80131904): 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)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5341687
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5353471
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +923
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +311
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +646
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +5356769
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +732
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1057
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +196
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +146
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +16
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +94
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +110
System.Data.SqlClient.SqlConnection.Open() +96
MasterPage.Page_Load(Object sender, EventArgs e) in c:\inetpub\vhosts\egitimderehberlik.net\httpdocs\MasterPage.master.cs:22
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Control.LoadRecursive() +145
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

22 03 2016
serhat

sorun ne anlayamadım master page de connectıon strıng hatası dıyor ama sorun yok gıbı

SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings[0].ConnectionString);
String sorgu = “Select * from KoseYazilari order by KoseYazilariTarih”;
SqlCommand cmd = new SqlCommand(sorgu, cnn);
cnn.Open();
SqlDataReader dr = cmd.ExecuteReader();

lstKoseYazilari.DataSource = dr;
lstKoseYazilari.DataBind();
cnn.Close();

Bir Cevap Yazın

Aşağıya bilgilerinizi girin veya oturum açmak için bir simgeye tıklayın:

WordPress.com Logosu

WordPress.com hesabınızı kullanarak yorum yapıyorsunuz. Log Out / Değiştir )

Twitter resmi

Twitter hesabınızı kullanarak yorum yapıyorsunuz. Log Out / Değiştir )

Facebook fotoğrafı

Facebook hesabınızı kullanarak yorum yapıyorsunuz. Log Out / Değiştir )

Google+ fotoğrafı

Google+ hesabınızı kullanarak yorum yapıyorsunuz. Log Out / Değiştir )

Connecting to %s




%d blogcu bunu beğendi: