Showing posts with label config. Show all posts
Showing posts with label config. Show all posts

Thursday, March 22, 2012

ConnectionString using SQL Server

Hello all,

I tried several connectionstrings in web.config file shown below and got this error "Application Error" (ErrorPage.htm).

<add name="ClubSiteDB" connectionString="Data Source=myClubs;Initial Catalog=Clubs;User Id=xxxx;Password=xxxx;" providerName="System.Data.SqlClient"/>
<add name="ClubSiteDB" connectionString="Driver={SQL Server};Server=localhost;Database=clubs;Uid=xxxx;Pwd=xxxx;" providerName="System.Data.SqlClient"/>

I created SQL Server 2000 database called clubs and ODBC DSN called myClubs at web hosting. It worked at local machine with no problem, but transfer from local machine to web hosting is something I'm not familiar with. Please advice. Thanks.

EagleGolf

check out www.connectionstrings.com|||

Hi!,

U have to specify the server name rather than 'localhost', if u r using trusted connection then it should be:
Database=Test;Server=Machine1;Trusted_Connection=Yes,
If not then specify the Userid and password:
server=Machine1;database=test;uid=xxx;pwd=xxx

Hope this will help
Regards

|||

The server name would be the url connected to the database. Or just the name like .\SQLEXPRESS? I use your method and it didn't work like it should.

|||

Hi,

Are u using SQL Express? If yes, then check this URL:

http://www.eggheadcafe.com/articles/20060719.asp

Hope this will help.

Regards

|||

I finally figured it out. I had the server name wrong and now it is corrected. Thanks for all of your help. Have a nice day.

Thursday, March 8, 2012

connection to SQL from asp.net page

I am using an asp.net page with vb.net. The following connection in my web.config file will connect the database to my page no problem:

"Data Source=MIAPPS1;Initial Catalog=MASTER_DB;Integrated Security=SSPI;"

However, when I add data to the page and try to preview it in the browser I get the following error:

"System.Data.SqlClient.SqlException: Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection."

I'm kind of perplexed as to why I can attach a database to my page, test the connection view data -but not be able to connect when previewing through the browser.

Any Ideas?

BillHave you added the ASP.NET account to the server server authorized logins?|||I have added an account ASPNET. Is it ASPNET or ASP.NET. The error message also showed, null for the login, does this still point to the ASPNET login issue?|||Yes. The errors means that you either trying to connected to SQL with SQL Authication while only Windows Authentication is enabled, or that the windows account you're using is not one enlisted into the sql logins account.

If you're using IIS5 the account is ASP.NET, if using IIS6 is the Network Service account

Sunday, February 19, 2012

Connection String for SQL 2005 Express

Hi,
My C# app uses SQL Server 2005 Express edition.
I store my connection string in a config file.
My application will run on numerous machines and therefore the machine name
will be different each time. What I would like is a generic connection strin
g
so that I don't have to change it each time I install my app on a different
machine.
I therefore want to avoid specifing the machine name in the connection
string as shown below :-
"Data Source=MachineName;Initial Catalog=pubs;Integrated Security=SSPI;"
Is there any way to make this connection string generic so that it can stay
the same between different machines?
Thanks
MaccaIf you run your application on the same machine as the database, . (period)
works as a server name. So if your install SQL Express with the default
instance name, the server name is .\SQLEXPRESS
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Macca" <Macca@.discussions.microsoft.com> wrote in message
news:B0A6D9FF-6715-4BBD-83BB-0C8B1F9A7098@.microsoft.com...
> Hi,
> My C# app uses SQL Server 2005 Express edition.
> I store my connection string in a config file.
> My application will run on numerous machines and therefore the machine
> name
> will be different each time. What I would like is a generic connection
> string
> so that I don't have to change it each time I install my app on a
> different
> machine.
> I therefore want to avoid specifing the machine name in the connection
> string as shown below :-
> "Data Source=MachineName;Initial Catalog=pubs;Integrated Security=SSPI;"
> Is there any way to make this connection string generic so that it can
> stay
> the same between different machines?
> Thanks
> Macca

Connection string Error

Hello I need some help please.

I created a connection string in my web config. I then tried to call it in one of my c# pages but I get a "System.InvalidOperationException: Instance failure" every time I run it.

Please review my code and let me know what I am doing wrong.

Thank you in advance for all the help

Web Config

<

appSettings>

<

addkey="AVConnection"value="Server=Server; Database=DB; User ID=sa; Password=PWD" />

</appSettings>

//////calling connection and running a simple SQL statment///////

protected void Page_Load(object sender, EventArgs e)

{

string ConnApp;

ConnApp = System.Configuration.ConfigurationManager.AppSettings["AVConnection"];

Response.Write(ConnApp);//the string is being passed this far

SqlConnection objConn = new SqlConnection(ConnApp);

SqlCommand sqlCMD = new SqlCommand("Select * FROM Employee", objConn);

objConn.Open();//this is where the error occures

SqlDataReader objRdr = sqlCMD.ExecuteReader();

Repeater1.DataSource = objRdr;

Repeater1.DataBind();

objConn.Close();

objRdr.Close();

}

ERROR PAGE

Line 29: SqlCommand sqlCMD = new SqlCommand("Select * FROM Employee", objConn);
Line 30:
Line 31: objConn.Open();
Line 32: SqlDataReader objRdr = sqlCMD.ExecuteReader();
Line 33: Repeater1.DataSource = objRdr;

[InvalidOperationException: Instance failure.]
System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) +683775
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +628
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +359
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +496
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
employeelist.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\FAUAV\employeelist.aspx.cs:31
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061


Don't know how much of a difference this might make, but have you tried putting the connection string in the connectionStrings node of web.config? If not you might as well do that as that's why it exists.

Ryan

|||

I tried that but it did not change anything.

Thanks for the advice