problem connecting to access database in asp.net 2.0 - asp.net

hi im trying to get a dataset from an access database
im using this connection string:
<connectionStrings>
<add name="SiteConnString" connectionString="Data Source=c:\inetpub\vhosts\db\mainDB.mdb"
providerName="Microsoft.Jet.OLEDB.4.0" />
</connectionStrings>
and this is my call to SqlHelper:
myDataSet = SqlHelper.ExecuteDataset(connString, CommandType.Text, strSQL);
and the error im getting is this:
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)

The providerName attribute expects an ADO.NET provider class name. Try changing your connection like so:
<connectionStrings>
<add name="SiteConnString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\vhosts\db\mainDB.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
A very handy reference for connection string formats is http://connectionstrings.com

Related

ASP.NET MVC network-related or instance-specific error

I am getting this 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: SQL Network Interfaces, error: 26
- Error Locating Server/Instance Specified)'
When I try to run my ASP.NET MVC project. Opening it for the first time on this PC.(I try to register a user and the database doesn't get created and I get the error above.) The database should get created the first time I hit the database PS: It's a code first project
I thought I know how to fix it until now.
The project runs on my other PC but on this not.
So I thought I'll go and change the connection string to
<connectionStrings>
<add name="foo"
providerName="System.Data.EntityClient"
connectionString="Data Source=localhost"/>
</connectionStrings>
(just change the Data Source= to localhost)
The constructor in my DbContext is
public EventManagerDbContext() : base("foo")
{
}
Still I can't run my project.
PS: I am able to connect to my database using the SQL Server Management Studio, but not from the project. Why is that?
I realised that the problem was that my connection string was placed in the Data Access Layer. But it has to be in the ASP.NET MVC application right? Would like some clarification.
Provide a complete details to your connectionstring like this:
<add name="foo" connectionString="Data Source=.\SQLEXPRESS2014;Initial Catalog=NameOfYourDB;
Integrated Security=True;"
providerName="System.Data.SqlClient" />
I suppose that your localhost is .\SQLEXPRESS2014 is your local machine server name.
To get the full server name on your part, connect to server, under Server Name, choose Browse for more option, then select Network Servers tab, and it will list your qualified server name:

Web config error with two databases in asp.net

I develop a website and there are two databases in my web site.
I made two database and users in plesk panel and upload the back ups,
database the first name is database_Journal and database name 2 is database_General and also the users are UserID1 and UserID.
But there is some thing wrong in it and it gave me this error:
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)
My web config is like this:
<add name="dbconn" connectionString="Password==******;; Persist Security Info=True;User ID=UserID1; Initial Catalog=database_General; Data Source=***.**.**.**" providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Password=******;Persist Security Info=True;User ID=UserID1; Initial Catalog=database_General; Data Source=***.**.**.**" providerName="System.Data.SqlClient" />
<add name="dbconn_general" connectionString="Password==******;; Persist Security Info=True;User ID=UserID; Initial Catalog=database_Journal; Data Source=***.**.**.**" providerName="System.Data.SqlClient" />
Try this format...
<add name="dbconn" connectionString="server=YourServerNameOrServerIpAddress; database=database_General; uid=UserID1; Password=******" providerName="System.Data.SqlClient" />

Cannot connect to mysql database in .NET MVC3

I've having some trouble in connecting mvc 3 application in .net. I know that mysql database instance has to be created before using web.config file to connect the it. My
connectionStrings as below:
<connectionStrings>
<add name="epmsDb"
connectionString="Server=localhost;Database=database1;
Uid=root;Pwd=mypassword"
providerName="System.Data.SqlClient" />
</connectionStrings>
and I've got a database name call epmsDb created in Server explorer. Then I tried to get the connectionString in the code using this :
string connectionString =
ConfigurationManager.ConnectionStrings["epmsDb"].ConnectionString;
context = new DataContext(connectionString);
usersTable = context.GetTable<UserObj>();
Every time I tried to access the database, I threw this exception:
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)
I've been trying to overcome this for a week now. Does anyone have ideas why this occurres?
Your example tries to connect to an MS SQL database. To connect to a MySQL DB you might want to use the MySQL connector
Then change the ProviderName property:
<connectionStrings>
<add name="epmsDb"
connectionString="Server=localhost;Database=database1;
Uid=root;Pwd=mypassword"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>

Why is the SPA application not creating a database?

I have followed a microsoft video trying to make the single page application and it doesnt create or connect to my sql instance even though I have other applications using code first. For example the connection string was...
<add name="DefaultConnection" connectionString="Data Source=Localhost;Initial Catalog=aspnet-MvcApplication2-201265113324;Integrated Security=True" providerName="System.Data.SqlClient" />
But I get an error saying
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)
Its really strange because my other application with the connectionstring...
<add name="PteDotNetContext" providerName="System.Data.SqlClient" connectionString="Server=Localhost;Database=PteDotNet;Trusted_Connection=true;" />
Works fine and will connect no problem...
If you do not provide a connection string or connection string name to the DbContext constructor, it will try to find a connection name that matches the (inherited) DbContext class name.
Hence you can either change the name of the connection string
<add name="MyDbContext" connectionString="Data Source=Localhost;Initial Catalog=aspnet-MvcApplication2-201265113324;Integrated Security=True" providerName="System.Data.SqlClient" />
Or provide the name of the connection string in the constructor
public class MyDbContext : DbContext
{
public MyDbContext() : base("DefaultConnection") {}
}

MY ASPNETDB.MDF would not work in production server? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
A network-related or instance-specific error occurred while establishing a connection to SQL Server.
Today i have create two pages login.aspx using LOgin control and register.aspx using Create user wizard ...
when i use connection string of my production server in my local computer then site works only if my database ASPNETDB.MDF is present in APP_Data Folder in my local computer..
if i rename ASPNETDB.MDF or Delete ASPNETDB.MDF from my local compuet App_Data the the following error occurs ...
An attempt to attach an auto-named database for file C:\Users\Ashish Dobriyal\Documents\Visual Studio 2008\WebSites\VOLVOO\App_Data\ASPNETDB.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
but
After i publish my webpages ..... and database to my production server .... it produces an error ....
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)
What was the problem actually ... ??
MY PRODUCTION SERVER CONNECTION STRING :
<connectionStrings>
<remove name="ConnectionString"/>
<add name="ConnectionString" connectionString="workstation id=volvobusesindia.mssql.somee.com;packet size=4096;user id=username;pwd=password;data source=dobriyal.mssql.somee.com;persist security info=False;initial catalog=dobriyal" providerName="System.Data.SqlClient"/>
</connectionStrings>
MY LOCAL SERVER CONNECTION STRING :
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
when i use connection string of my
production server in my local computer
then site works only if my database
ASPNETDB.MDF is present in APP_Data
Folder in my local computer..
This is because you need to add access permissions to the directory that you going to put the database. The permissions must be for the user that runs the asp.net pool that you using.
Alternative try this string, for both production and local server and just be sure that your database have the correct permissions for been access from the asp.net running pool account.
This is not depended from what you write on the string but from how you correctly setup the database. Its working 100% so if not play for you search the database permissions, both file and database settings.
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=localhost;Initial Catalog=dobriyal;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

Resources