I'm coding project Using MS Visual Studio 2017 to enter data to sql Database. when i'm publish the project to another pc its can't connection to sql database show error like image below . the connection string =
SqlConnection conn = new SqlConnection(#"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|Car_db.mdf;Integrated Security=True");
Related
I am migrating my Webappserver from SQL2012Express to SQL2016Enterprise.
for this I have installed a Windows server 2016 with IIS10 my current IIS db connection String is
"data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
this is on Windows 2008 and IIS 7 with SQL 2012 Express.
Now on the new webappserver my source is no longer SQLexpress since the SQL is enterprise not express. my instance name was SQL2012 I changed it to Sql2016 in my Software's web.config and IIS as well I am not able to connect my software to the Database.
Here is what my current Db String is on the current webappserver.
My SQL management Studio is
On the New Server My ISS db connection string is the same which is express?
and my SQL Studio properties are
My connection string in my MVC app web.config file is
I hope I am giving you enough information to help me on this challenge I am facing.
This is my first time migrating SQL server and I am sure I have create the instance correctly.
my connection String to the site on IIS is
data source=.\SQL2016;Integrated Security=True;App=Worldwide;Initial Catalog=Worldwide
Any Help is very, very appreciate it.
Thank you.
I've created a new DB on my local PC in SQL Server 2012 Express (also installed locally), through Visual Studio's SQL Server Object Explorer window. I don't really know anything about SQL Server but I can see that .MDF and .LDF files are created.
I want to add a connection to this DB through "add Data Source" but if I try to connect using the DB name, I get this error:
And if I try to connect by selecting the MDF file I get this error:
How VS and SQL Server are interacting is not clear to me - is it telling me I cannot open the .MDF file because it's already open by SQL Server? Should I even be connecting to the file, or to the DB name?
I think SQL Server is actually running since the DB shows up in VS but as I'm new to it, I'm not certain... here's what the Configuration tool shows:
I am new to .NET technology and I am using Visual Studio 2012 and .net framework 4.5. I tried SQL Server 2008 but I'm unable to connect to it with server name . and .\SQLEXPRESS.
Which version of SQL Server should I install for database access and please provide the link for same?
VS.NET 2012 ships with SQL Server 2012 Express LocalDb. If you use LocalDb and its file is located in App_Data\DatabaseFileName.mdf then you could connect using
<add name="ConnectionStringName"
providerName="System.Data.SqlClient"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFileName=|DataDirectory|\DatabaseFileName.mdf;InitialCatalog=DatabaseName;Integrated Security=True" />
To see what database is in use you can either from VS.NET or using SQL Server Management Studio
If you use other database, e.g. SQL Server 2008, you need to make sure that
name of the server and the SQL Server instance
server is up and running
You can use ".", "(local)", or "localhost" in place of the server name to specify the local computer, but you need to make sure that server is there.
Open SQL Server Management Studio, Connect to Server and see the name of the server and its authentication type. If it is a Windows Authentication you can use Integrated Security=True in the connection string.
Example:
using System.Data.SqlClient;
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = #"Data Source=\SQLEXPRESS;Initial Catalog=DBNAME_HERE;Integrated Security=True";
using (SqlConnection objSqlConnection = new SqlConnection(connectionString))
{
try {
objSqlConnection.Open();
objSqlConnection.Close();
Response.Write("Connection is successfull");
} catch (Exception ex) {
Response.Write("Error : " + ex.Message.ToString());
}
}
}
Reed more here.
Microsoft SQL Server 2012 Express have the following limitations:
Maximum database size 10GB
Maximum usage of Ram 1GB
Single physical CPU
No SQL Server Agent (job scheduler)
Profiler tool is not included
Also, your connection string should be something like this:
Server=.\SQLExpress;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname;
Trusted_Connection=Yes;
I have successfully migrated all my databases from 2008 to 2012 and mapped the user to the specific databases.
My problem being is 2008 expired (hence why I got 2012) and I was using a web service to call/edit data in the tables.
When I run a web service function it just times out which suggests to me that it is still trying to talk to 2008.
I am using -
using System.Data.OleDb;
using System.Data.SqlClient;
with connection -
OleDbConnection objConnection = null;
OleDbCommand objCmd = null;
String strConnection, strSQL;
strConnection = "Provider=sqloledb;Data Source=.;Initial Catalog=NSN;User Id=userID;Password=password;Connect Timeout=300";
My question being, how can I tell the web service to point at SQL server 2012 now that I have migrated all the databases?
If your SQL Server 2008 has expired why dont you then remove the access for the user mentioned in your connection string to the SQL 2008 Db or best make it offline. If the application fails then you know that it was still pointing to SQL2008.
Try to change your connection string to the following:
strConnection = "Provider=sqloledb;Data Source=.\<INSTANCENAME>;Initial Catalog=NSN;User Id=userID;Password=password;Connect Timeout=300";
Where is the name of your SQL Server 2012 instance. It should be the same as you type in the 'Server name' in management studio login dialog.
The problem is that you are trying to connect to the default instance which is your SQL Server 2008 installation.
I'm currently upgrading my sql server from 2005 to 2008 enterprise server. I used VB to connect to the database. It worked fine in the previous version of sql, but when upgrading it seems doesn't recognize my connection string.
Below is my connection string:
myConnection = New SqlConnection("server=RAVY-PC\RAVY;uid=;pwd=;database=CIEDC");
myConnection.Open();
Where Ravy-PC\RAVY is my server name at the sql server login dialogue box. And I used the windows authentication mode.
Any help would be appreciated. Thanks guy for viewing....
Try this connection string:
Server=RAVY-PC\RAVY;Database=CIEDC;Trusted_Connection=True;